$url = 'https://callapi.asanak.com/v1/upload/voice';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://callapi.asanak.com/v1/upload/voice',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => array('username' => 'USERNAME','password' => 'PASSWORD','file'=> new CURLFILE('/C:/Music/beep-01a.mp3')),
CURLOPT_HTTPHEADER => array(
'Content-Type: multipart/form-data'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
curl --location 'https://callapi.asanak.com/v1/upload/voice' \
--header 'Content-Type: multipart/form-data' \
--form 'username="USERNAME"' \
--form 'password="PASSWORD"' \
--form 'file=@"/C:/Music/beep-01a.mp3"'
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://callapi.asanak.com/v1/upload/voice");
var content = new MultipartFormDataContent();
content.Add(new StringContent("USERNAME"), "username");
content.Add(new StringContent("PASSWORD"), "password");
content.Add(new StreamContent(File.OpenRead("/C:/Music/beep-01a.mp3")), "file", "/C:/Music/beep-01a.mp3");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("multipart/form-data");
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
.addFormDataPart("username","USERNAME")
.addFormDataPart("password","PASSWORD")
.addFormDataPart("file","/C:/Music/beep-01a.mp3",
RequestBody.create(MediaType.parse("application/octet-stream"),
new File("/C:/Music/beep-01a.mp3")))
.build();
Request request = new Request.Builder()
.url("https://callapi.asanak.com/v1/upload/voice")
.method("POST", body)
.addHeader("Content-Type", "multipart/form-data")
.build();
Response response = client.newCall(request).execute();
import requests
url = "https://callapi.asanak.com/v1/upload/voice"
payload = {'username': 'USERNAME',
'password': 'PASSWORD'}
files=[
('file',('beep-01a.mp3',open('/C:/Music/beep-01a.mp3','rb'),'audio/mpeg'))
]
headers = {
'Content-Type': 'multipart/form-data'
}
response = requests.request("POST", url, headers=headers, data=payload, files=files)
print(response.text)
package main
import (
"fmt"
"bytes"
"mime/multipart"
"os"
"path/filepath"
"net/http"
"io"
)
func main() {
url := "https://callapi.asanak.com/v1/upload/voice"
method := "POST"
payload := &bytes.Buffer{}
writer := multipart.NewWriter(payload)
_ = writer.WriteField("username", "USERNAME")
_ = writer.WriteField("password", "PASSWORD")
file, errFile3 := os.Open("/C:/Music/beep-01a.mp3")
defer file.Close()
part3,
errFile3 := writer.CreateFormFile("file",filepath.Base("/C:/Music/beep-01a.mp3"))
_, errFile3 = io.Copy(part3, file)
if errFile3 != nil {
fmt.Println(errFile3)
return
}
err := writer.Close()
if err != nil {
fmt.Println(err)
return
}
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "multipart/form-data")
req.Header.Set("Content-Type", writer.FormDataContentType())
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://callapi.asanak.com/v1/upload/voice"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:10.0];
NSDictionary *headers = @{
@"Content-Type": @"multipart/form-data"
};
[request setAllHTTPHeaderFields:headers];
NSArray *parameters = @[
@{ @"name": @"username", @"value": @"USERNAME" },
@{ @"name": @"password", @"value": @"PASSWORD" },
@{ @"name": @"file", @"fileName": @"/C:/Music/beep-01a.mp3" }
];
NSString *boundary = @"----WebKitFormBoundary7MA4YWxkTrZu0gW";
NSError *error;
NSMutableString *body = [NSMutableString string];
for (NSDictionary *param in parameters) {
[body appendFormat:@"--%@\r\n", boundary];
if (param[@"fileName"]) {
[body appendFormat:@"Content-Disposition:form-data; name=\"%@\"; filename=\"%@\"\r\n", param[@"name"], param[@"fileName"]];
[body appendFormat:@"Content-Type: %@\r\n\r\n", param[@"contentType"]];
[body appendFormat:@"%@", [NSString stringWithContentsOfFile:param[@"fileName"] encoding:NSUTF8StringEncoding error:&error]];
if (error) {
NSLog(@"%@", error);
}
} else {
[body appendFormat:@"Content-Disposition:form-data; name=\"%@\"\r\n\r\n", param[@"name"]];
[body appendFormat:@"%@", param[@"value"]];
}
}
[body appendFormat:@"\r\n--%@--\r\n", boundary];
NSData *postData = [body dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:postData];
[request setHTTPMethod:@"POST"];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
NSLog(@"%@", error);
dispatch_semaphore_signal(sema);
} else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSError *parseError = nil;
NSDictionary *responseDictionary = [NSJSONSerialization JSONObjectWithData:data options:0 error:&parseError];
NSLog(@"%@",responseDictionary);
dispatch_semaphore_signal(sema);
}
}];
[dataTask resume];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
let data = new FormData();
data.append('username', 'USERNAME');
data.append('password', 'PASSWORD');
data.append('file', fs.createReadStream('/C:/Users/Sazgar/Music/beep-01a.mp3'));
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'https://callapi.asanak.com/v1/upload/voice',
headers: {
'Content-Type': 'multipart/form-data',
...data.getHeaders()
},
data : data
};
axios.request(config)
.then((response) => {
console.log(JSON.stringify(response.data));
})
.catch((error) => {
console.log(error);
});
require "uri"
require "net/http"
url = URI("https://callapi.asanak.com/v1/upload/voice")
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = "multipart/form-data"
form_data = [['username', 'USERNAME'],['password', 'PASSWORD'],['file', File.open('/C:/Music/beep-01a.mp3')]]
request.set_form form_data, 'multipart/form-data'
response = https.request(request)
puts response.read_body
#[tokio::main]
async fn main() -> Result<(), Box> {
let client = reqwest::Client::builder()
.build()?;
let mut headers = reqwest::header::HeaderMap::new();
headers.insert("Content-Type", "multipart/form-data".parse()?);
let form = reqwest::multipart::Form::new()
.text("username", "USERNAME")
.text("password", "PASSWORD")
.part("file", reqwest::multipart::Part::bytes(std::fs::read("/C:/Users/Sazgar/Music/beep-01a.mp3")?).file_name("/C:/Users/Sazgar/Music/beep-01a.mp3"));
let request = client.request(reqwest::Method::POST, "https://callapi.asanak.com/v1/upload/voice")
.headers(headers)
.multipart(form);
let response = request.send().await?;
let body = response.text().await?;
println!("{}", body);
Ok(())
}