Closed apoorvdwi closed 5 months ago
@animator you can run the below 2 codes to verify. It will print the request headers being sent
With explicit content type set
use curl::easy::{Easy, InfoType, List};
fn main() {
let mut easy = Easy::new();
let mut data = Vec::new();
easy.url("https://api.apidash.dev/io/form").unwrap();
easy.verbose(true).unwrap();
easy.post(true).unwrap();
let mut form = curl::easy::Form::new();
form.part("text").contents(b"API").add().unwrap();
form.part("sep").contents(b"|").add().unwrap();
form.part("times").contents(b"3").add().unwrap();
let mut list = List::new();
list.append("Content-Type: multipart/form-data").unwrap();
easy.http_headers(list).unwrap();
easy.httppost(form).unwrap();
easy.debug_function(|info_type, data| {
if let InfoType::HeaderOut = info_type {
print!("Request header:\n{}", String::from_utf8_lossy(data));
}
})
.unwrap();
{
let mut transfer = easy.transfer();
transfer
.write_function(|new_data| {
data.extend_from_slice(new_data);
Ok(new_data.len())
})
.unwrap();
transfer.perform().unwrap();
}
let response_body = String::from_utf8_lossy(&data);
println!("Response body: {}", response_body);
println!("Response code: {}", easy.response_code().unwrap());
}
Without explicit content type set
use curl::easy::{Easy, InfoType};
fn main() {
let mut easy = Easy::new();
let mut data = Vec::new();
easy.url("https://api.apidash.dev/io/form").unwrap();
easy.verbose(true).unwrap();
easy.post(true).unwrap();
let mut form = curl::easy::Form::new();
form.part("text").contents(b"API").add().unwrap();
form.part("sep").contents(b"|").add().unwrap();
form.part("times").contents(b"3").add().unwrap();
easy.httppost(form).unwrap();
easy.debug_function(|info_type, data| {
if let InfoType::HeaderOut = info_type {
print!("Request header:\n{}", String::from_utf8_lossy(data));
}
})
.unwrap();
{
let mut transfer = easy.transfer();
transfer
.write_function(|new_data| {
data.extend_from_slice(new_data);
Ok(new_data.len())
})
.unwrap();
transfer.perform().unwrap();
}
let response_body = String::from_utf8_lossy(&data);
println!("Response body: {}", response_body);
println!("Response code: {}", easy.response_code().unwrap());
}
LGTM
PR Description
Added curl rust code generator and corresponding test file
Related Issues
Checklist
main
branch before making this PRflutter test
) and all tests are passingAdded/updated tests?
We encourage you to add relevant test cases.