curl --request POST \ --url http://cloudapi.deepfinch.com/car/vehicle_recognition \ --header 'content-type: multipart/form-data; boundary=---011000010111000001101001' \ --header 'X-DF-API-ID: xxxxxxxxxxxxxxxxxxxx' \ --header 'X-DF-API-SECRET: xxxxxxxxxxxxxxxxxxxx' \ --form file=1.jpg
package main import ( "fmt" "strings" "net/http" "io/ioutil" ) func main() { url := "http://cloudapi.deepfinch.com/car/vehicle_recognition" payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"\r\n\r\n1.jpg\r\n-----011000010111000001101001--\r\n") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("X-DF-API-ID", "xxxxxxxxxxxxxxxxxxxx") req.Header.Add("X-DF-API-SECRET", "xxxxxxxxxxxxxxxxxxxx") req.Header.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) }
OkHttpClient client = new OkHttpClient(); MediaType mediaType = MediaType.parse("multipart/form-data; boundary=---011000010111000001101001"); RequestBody body = RequestBody.create(mediaType, "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"\r\n\r\n1.jpg\r\n-----011000010111000001101001--\r\n"); Request request = new Request.Builder() .url("http://cloudapi.deepfinch.com/car/vehicle_recognition") .post(body) .addHeader("X-DF-API-ID", "xxxxxxxxxxxxxxxxxxxx") .addHeader("X-DF-API-SECRET", "xxxxxxxxxxxxxxxxxxxx") .addHeader("content-type", "multipart/form-data; boundary=---011000010111000001101001") .build(); Response response = client.newCall(request).execute();
addForm(array( 'file' => '1.jpg' ), NULL); $request->setRequestUrl('http://cloudapi.deepfinch.com/car/vehicle_recognition'); $request->setRequestMethod('POST'); $request->setBody($body); $request->setHeaders(array( 'X-DF-API-ID' => 'xxxxxxxxxxxxxxxxxxxx', 'X-DF-API-SECRET' => 'xxxxxxxxxxxxxxxxxxxx' )); $client->enqueue($request)->send(); $response = $client->getResponse(); echo $response->getBody();
import requests url = "http://cloudapi.deepfinch.com/car/vehicle_recognition" payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"\r\n\r\n1.jpg\r\n-----011000010111000001101001--\r\n" headers = { 'X-DF-API-ID': "xxxxxxxxxxxxxxxxxxxx", 'X-DF-API-SECRET': "xxxxxxxxxxxxxxxxxxxx", 'content-type': "multipart/form-data; boundary=---011000010111000001101001" } response = requests.request("POST", url, data=payload, headers=headers) print(response.text)
require 'uri' require 'net/http' url = URI("http://cloudapi.deepfinch.com/car/vehicle_recognition") http = Net::HTTP.new(url.host, url.port) request = Net::HTTP::Post.new(url) request["X-DF-API-ID"] = 'xxxxxxxxxxxxxxxxxxxx' request["X-DF-API-SECRET"] = 'xxxxxxxxxxxxxxxxxxxx' request["content-type"] = 'multipart/form-data; boundary=---011000010111000001101001' request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"\r\n\r\n1.jpg\r\n-----011000010111000001101001--\r\n" response = http.request(request) puts response.read_body
#importNSDictionary *headers = @{ @"X-DF-API-ID": @"xxxxxxxxxxxxxxxxxxxx", @"X-DF-API-SECRET": @"xxxxxxxxxxxxxxxxxxxx", @"content-type": @"multipart/form-data; boundary=---011000010111000001101001" }; NSArray *parameters = @[ @{ @"name": @"file", @"value": @"1.jpg" } ]; NSString *boundary = @"---011000010111000001101001"; 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]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://cloudapi.deepfinch.com/car/vehicle_recognition"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0]; [request setHTTPMethod:@"POST"]; [request setAllHTTPHeaderFields:headers]; [request setHTTPBody:postData]; NSURLSession *session = [NSURLSession sharedSession]; NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { if (error) { NSLog(@"%@", error); } else { NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; NSLog(@"%@", httpResponse); } }]; [dataTask resume];
import Foundation let headers = [ "X-DF-API-ID": "xxxxxxxxxxxxxxxxxxxx", "X-DF-API-SECRET": "xxxxxxxxxxxxxxxxxxxx", "content-type": "multipart/form-data; boundary=---011000010111000001101001" ] let parameters = [ [ "name": "file", "value": "1.jpg" ] ] let boundary = "---011000010111000001101001" var body = "" var error: NSError? = nil for param in parameters { let paramName = param["name"]! body += "--\(boundary)\r\n" body += "Content-Disposition:form-data; name=\"\(paramName)\"" if let filename = param["fileName"] { let contentType = param["content-type"]! let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8) if (error != nil) { print(error) } body += "; filename=\"\(filename)\"\r\n" body += "Content-Type: \(contentType)\r\n\r\n" body += fileContent } else if let paramValue = param["value"] { body += "\r\n\r\n\(paramValue)" } } let request = NSMutableURLRequest(url: NSURL(string: "http://cloudapi.deepfinch.com/car/vehicle_recognition")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume()