I am using multipart/form-data
to upload an image (in two format image and json). This is working fine in POSTMAN and I'm getting a HTTP 201 (created) status in the response.
But when I am generating code from postman which is shown below, it's not working in Visual Studio 2017 causing a "Bad Request"
var client = new RestClient(url);
var request = new RestRequest(Method.POST);
request.AddHeader("Postman-Token", "dc097595-15fa-40ff-b968-51c1ec73e27a");
request.AddHeader("cache-control", "no-cache");
request.AddHeader("Authorization", "Bearer" + " " + token);
request.AddHeader("Content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
//request.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"image\"; filename=\""+ imageLocation + "\"\r\nContent-Type: image/jpeg\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"face\"; filename=\"" + faceLocation + "\"\r\nContent-Type: application/json\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
request.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"image\"; filename=\"C:\\IDEMIA\\SVN_2\\FacialRecognitionApplication\\Images\\3_image.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"face\"; filename=\"C:\\IDEMIA\\SVN_2\\FacialRecognitionApplication\\Images\\3_face.json\"\r\nContent-Type: application/json\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
-------vs code which show "Bad request"--------------
var client = new RestClient(url);
var request = new RestRequest(Method.POST);
request.AddHeader("Postman-Token", "dc097595-15fa-40ff-b968-51c1ec73e27a");
request.AddHeader("cache-control", "no-cache");
request.AddHeader("Authorization", "Bearer" + " " + token);
request.AddHeader("Content-type", "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
request.AddParameter("multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW", "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"image\"; filename=\"C:\\IDEMIA\\SVN_2\\FacialRecognitionApplication\\Images\\3_image.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"face\"; filename=\"C:\\IDEMIA\\SVN_2\\FacialRecognitionApplication\\Images\\3_face.json\"\r\nContent-Type: application/json\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
-----fiddler >textView>---- ------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="image"; filename="C:\IDEMIA\SVN_2\FacialRecognitionApplication\Images\3_image.jpg" Content-Type: image/jpeg
------WebKitFormBoundary7MA4YWxkTrZu0gW Content-Disposition: form-data; name="face"; filename="C:\IDEMIA\SVN_2\FacialRecognitionApplication\Images\3_face.json" Content-Type: application/json
------WebKitFormBoundary7MA4YWxkTrZu0gW--
----------Fiddler Response >Textview---
b5 {"constraintViolations":[{"message":"may not be null","messageTemplate":"{javax.validation.constraints.NotNull.message}","node":"arg1"}],"id":"385951b4-7220-4e28-9099-dcbb9d61d2c8"} 0
Comments
Post a Comment