HttpRequest.Saveas saves the following in a file
POST /VoicetrustAP/call.aspx HTTP/1.1
Cache-Control: max-age=3600, max-stale=0
Content-Length: 31988
Content-Type: multipart/form-data; boundary=osb_inet_multipart_boundary
Accept: */*
Expect: 100-continue
Host: 172.20.143.166
Referer: http://172.20.143.166/VoicetrustAP/call.aspx
User-Agent: AvayaVXI/2.0
--osb_inet_multipart_boundary
Content-Disposition: form-data; name="audioDataStream"; filename=20090313115600.ulaw
Content-Type: audio/x-wav
Content-Length: 31578
RIFFR{ WAVEfmt # # fact { data { ...data removed....
--osb_inet_multipart_boundary
Content-Disposition: form-data; name="callID"
00000056
--osb_inet_multipart_boundary
Content-Disposition: form-data; name="nextDialogID"
VTDC_CHECK_TD_AUDIO_DATA_ENR
--osb_inet_multipart_boundary--
But HttpRequest.Files.Count is less than zero ? Why?
Is it a bug in HttpRequest.Files?
Also I am able to access the data using formvariables. why?
I suspect although I haven't test it myself that a "less than zero" count actually means "I don't know how many files there are, I have received all of the incoming data stream yet".
Related
I have the contents of an http request saved on disk.
It looks like this:
POST http://test.ca/ 1.1
Accept: application/xml
Content-Type: multipart/form-data; boundary="8942d141-7753-45ab-be3a-53021694e70c"
--8942d141-7753-45ab-be3a-53021694e70c
Content-Type: application/xml Content-Disposition: form-data; name=Bundle
...
--8942d141-7753-45ab-be3a-53021694e70c
Content-Type: image/jpg Content-Disposition: form-data; name="image 1 of 2"; filename=Attachment1.jpg; filename*=utf-8''Attachment1.jpg
...
--8942d141-7753-45ab-be3a-53021694e70c--
Normally, if you were processing this at the time of request, the HttpRequest object would be used to get the content type. If I have that request persisted to disk, are there any available classes I can use to handle parsing the ContentType for me?
Everything else can be parsed using the MultipartReader class, but I'm not aware of anything that will handle parsing the request header, given an instance of a stream. If I don't have to roll my own that would be great.
I am getting content-Type: text/plain; charset=UTF-8
Content-Length: 1
in the parsed value for multipart data
when parsing the data
I have used below parser class
https://bitbucket.org/lorenzopolidori/http-form-parser/src/a48defaac3b2c8a4b89152bffb8a2eb33ad57e53/HttpMultipartParser.cs?at=default
I have a key named user_id with value "3"
but when parsing I am seeing additional data (headers ) along with value "3"
Response is like this
content-Type: text/plain; charset=UTF-8
Content-Length: 1
Content-Transfer-Encoding: binary
3
I have a problem with sending a POST request through WebClient in C# API.
The POST request is:
POST http://aaa.com/login.php HTTP/1.1
Host: www.aaa.com
Connection: keep-alive
Content-Length: 346
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Origin: http://www.aaa.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.152 Safari/537.22
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryK0J3zdRYpjgldAFy
Referer: http://www.turbotrafficbooster.com/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: bg-BG,bg;q=0.8
Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.3
Cookie: PHPSESSID=b703525853495c9257b3f3ec579c937a
------WebKitFormBoundaryK0J3zdRYpjgldAFy
Content-Disposition: form-data; name="navaction"
login
------WebKitFormBoundaryK0J3zdRYpjgldAFy
Content-Disposition: form-data; name="UserID"
test
------WebKitFormBoundaryK0J3zdRYpjgldAFy
Content-Disposition: form-data; name="Password"
test
------WebKitFormBoundaryK0J3zdRYpjgldAFy--
I know what to do with the headers like user-agent and etc., but I have a problem with the boundaries. I don't know how to put them and where to do it..
See this answer and the examples in the linked specification here. Example:
Content-Type: multipart/form-data; boundary=AaB03x
--AaB03x
Content-Disposition: form-data; name="submit-name"
Larry
--AaB03x
WebKitFormBoundaryK0J3zdRYpjgldAFy is just a convention. It could be MyFoobaredBoundry if you want, provided that that you declare and close it off appropriately. Different browsers use different strings, so nothing on the receiving end should differentiate because of it.
However, this is probably not something you have to do yourself...
I've been struggling to get the upload file post to work. All I get is a 404 not found error which isn't helping. I'm using C# HttpWebRequest. When I catch the request in fiddler this is what it looks like.
--
POST https://api.box.com/2.0/files/content HTTP/1.1
Authorization: BoxAuth api_key=APK_KEY&auth_token=AUTH_TOKEN
Content-Type: multipart/form-data; boundary=----------------------------8cfa73fa0212bf1
Host: api.box.com
Content-Length: 198082
------------------------------8cfa73fa0212bf1
------------------------------8cfa73fa0212bf1
Content-Disposition: form-data; name="folder_id";
532901558
------------------------------8cfa73fa0212bf1
------------------------------8cfa73fa0212bf1
Content-Disposition: form-data; name="filename"; filename="Pasha.pdf"
Content-Type: application/pdf
%PDF-1.5
%����
1 0 obj
<</Type/Catalog/Pages 2 0 R/Lang(en-CA) /StructTreeRoot 29 0 R/MarkInfo<</Marked true>>>>
endobj
2 0 obj
// rest of file data goes here ... too long to post
------------------------------8cfa73fa0212bf1
This is example of request what do you need to send to box.com
POST https://api.box.com/2.0/files/content HTTP/1.1
Authorization: BoxAuth api_key={key}&auth_token={token}
Content-Type: multipart/form-data; boundary="d174f29b-6def-47db-8519-3da38b21b398"
Host: api.box.com
Content-Length: 314
Expect: 100-continue
--d174f29b-6def-47db-8519-3da38b21b398
Content-Disposition: form-data; filename="hello.txt"; name="filename"
Content-Type: application/octet-stream
{Bytes}
--d174f29b-6def-47db-8519-3da38b21b398
Content-Disposition: form-data; name="folder_id"
0
--d174f29b-6def-47db-8519-3da38b21b398--
I have an issue similar to ASP.NET MVC 4 RC Web API Parameter Binding Issue, but I'm trying to solve it by using the [FromBody] attribute.
Fiddler reports the following request (excluding irrelevant bits like User Agent String)
PUT http://localhost:82/api/account/shoppinglistitems HTTP/1.1
Host: localhost:82
Connection: keep-alive
Content-Length: 11
Origin: http://localhost:3000
Content-Type: application/x-www-form-urlencoded
Accept: application/json, text/javascript, */*; q=0.01
query=apple
My controller action is
[HttpPut]
public ShoppingListItemWebModel CreateShoppingListItem([FromBody]string query) {
// query is null
}
I could wrap the parameter in a complex type, but that seems like a hack to fix the issue. Or I could put the query in the URI, but that doesn't fit the pattern of the rest of the API. Is it possible to do it this way? If so, where is my mistake?
change your request to be
PUT http://localhost:82/api/account/shoppinglistitems HTTP/1.1
Host: localhost:82
Connection: keep-alive
Content-Length: 11
Origin: http://localhost:3000
Content-Type: application/x-www-form-urlencoded
Accept: application/json, text/javascript, */*; q=0.01
=apple
notice the lack of "query"
If you're using AngularJS instead of jQuery you might want to opt for the following alternative, since AngularJS uses content type application/json by default.
PUT http://localhost:82/api/account/shoppinglistitems HTTP/1.1
Host: localhost:82
Connection: keep-alive
Content-Length: 7
Origin: http://localhost:3000
Content-Type: application/json
Accept: application/json, text/javascript, */*; q=0.01
'apple'
Notice that the value is wrapped in string quotes (either single or double).