如何发送此HttpWebRequest? [英] how to send this HttpWebRequest ?
问题描述
嘿,
第三方给了我一个从黑莓设备发送的http请求跟踪转储:
hey,
a 3rd party gave me an http request trace dump sent from a black berry device:
POST /maveo1 HTTP/1.1
Host: au1.blahblah.com.au:6226
Connection: close
User-Agent: mView1/4.3.0
Content-Length: 26
Command=SNAP&Timestamp=0
黑莓的代码是:(代码已更新)
the code at black berry is : (code updated)
HttpConnection httpConnection = (HttpConnection) Connector.open("http://" + _thrdOwner.getWebServiceURLforViewerAccount());
httpConnection.setRequestMethod(HttpConnection.POST);
httpConnection.setRequestProperty("User-Agent", "mView/4.3.0 (Blackberry OS)");
out = httpConnection.openOutputStream();
String sCommand = command1.toString() + "&" + command2.toString() + "="
+ value1.toString() + "" + value2.toString() + "\r\n";
out.write(sCommand.getBytes());
out.flush(); // This forces the POST to happen
responseCode = httpConnection.getResponseCode();
并要求我在按钮上单击上方的http请求来发送以触发一些命令,当我问他们可以给我一个uri或Web服务路径等时,他们说我们已经发送的内容就足够了.
我尝试执行以下操作,并且成功了:(代码已更新)
and asking me to send above http request on a button click on a web page to trigger some command, when I ask them can they give me a uri or web service path etc. They say what we have send is enough.
I tried doing the below and it worked: (Code Updated)
HttpWebRequest myHttpWebRequest =(HttpWebRequest)WebRequest.Create("http://au1.blahblah.com.au:6226/maveo1");
myHttpWebRequest.Method = "POST";
myHttpWebRequest.UserAgent = "mView/4.5.0";
string postData = "Command=SNAP&Timestamp=0\n";
ASCIIEncoding encoding = new ASCIIEncoding ();
byte[] byte1 = encoding.GetBytes (postData);
myHttpWebRequest.ContentLength = byte1.Length;
Stream newStream = myHttpWebRequest.GetRequestStream ();
newStream.Write (byte1, 0, byte1.Length);
newStream.Close ();
WebResponse resp = myHttpWebRequest.GetResponse();
所以我复制了如下的http请求:
so i reproduced the http reques like below:
POST /maveo/ HTTP/1.1
Host: au1.blahblah.com.au:6226
Content-Length: 24
Expect: 100-continue
HTTP/1.1 100 Continue
server: m-View HTTP Service/4.5.0.12
date: Tue, 07 Jun 2011 17:38:25 GMT
Command=SNAP&Timestamp=0HTTP/1.1 200 OK
server: m-View HTTP Service/4.5.0.12
date: Tue, 07 Jun 2011 17:38:25 GMT
connection: close
现在,您在http帖子中说期望:100-继续"可以消除它...
Now y the http post is saying ''Expect: 100-continue'' can we get rid of it...
推荐答案
我注意到您的代码未指定HttpWebRequest.Method
,必须为"POST
",具体取决于您要复制的HTTP转储.
回答后续问题:
HTTP标准的文本在此处说明了"Expect: 100-continue
"的使用:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html [ ^ ].
我认为您不需要摆脱它" :-).
—SA
I noticed your code does not specifyHttpWebRequest.Method
, with must be "POST
", according to your HTTP dump which you''re trying to reproduce.
Answering a follow-up question:
The use of "Expect: 100-continue
" is explained in the text of HTTP standard here:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html[^].
I don''t think you need to "get rid of it" :-).
—SA
这篇关于如何发送此HttpWebRequest?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!