XML HTTP [英] XML HTTP
问题描述
我正在尝试将XMl发布到URl但是当我测试它时,请求流中的文本似乎没有被发送:
//配置安全证书&凭证
req.ClientCertificates.Add(myCert);
req.Credentials = myCache;
//设置HTTP请求标头
req.Method =" POST";
req.ProtocolVersion = HttpVersion.Version11;
req.ContentLength = postdata.Length;
req.ContentType =" multipart / form-data;边界= [TGWLR]英寸;
req.KeepAlive = false;
req.Headers.Add(" Authorization",encCreds);
req.AllowWriteStreamBuffering = true;
//创建流编写器
Stream strWrite = req.GetRequestStream();
StreamWriter sw = new StreamWriter(strWrite) ;
//设置发布数据
字符串postdata =" \ n \\ nn - [TGWLR] \ n" ;;
postdata + =" Content-disposition:form-data;命名= \" tgtest001\英寸; filename = \" tgtest001.xml \" \ n";
postdata + =" Content-type:text / xml\\\
\\\
" ;;
postdata + ="<?xml version = \" 1.0 \" encoding = \" utf-8 \"?> \ n" ;;
postdata + = XML;
postdata + =" \ n - [TGWLR] - \ n\\\
" ;;
// POST XML ---这似乎不适合工作
sw .Write(postdata);
sw.Flush();
sw.Close();
任何线索的任何线索?
另外,如果有更简单/更好的方法可以让我知道吗?!
干杯,
Dave Hart
系统开发人员
Telco Global Ltd.
Hi,
I''m trying to post XMl to a URl but when I test it the text in the request stream doesn''t appear to get sent:
// Configure secure certificate & credentials
req.ClientCertificates.Add(myCert);
req.Credentials = myCache;
// Setup HTTP Request headers
req.Method = "POST";
req.ProtocolVersion=HttpVersion.Version11;
req.ContentLength = postdata.Length;
req.ContentType = "multipart/form-data; boundary=[TGWLR]";
req.KeepAlive=false;
req.Headers.Add("Authorization",encCreds);
req.AllowWriteStreamBuffering=true;
// Create stream writer
Stream strWrite = req.GetRequestStream();
StreamWriter sw = new StreamWriter(strWrite);
// Set up post data
String postdata = "\n\n--[TGWLR]\n";
postdata += "Content-disposition: form-data; name=\"tgtest001\"; filename=\"tgtest001.xml\"\n";
postdata += "Content-type: text/xml\n\n";
postdata += "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
postdata += XML;
postdata += "\n--[TGWLR]--\n\n";
// POST XML --- THIS DOES NOT APPEAR TO BE WORKING
sw.Write(postdata);
sw.Flush();
sw.Close();
Any clues anybody?
Also, if there''s an easier/better way of doing this can you let me know?!
Cheers,
Dave Hart
System Developer
Telco Global Ltd.
推荐答案
戴夫< da ** @ telco.co.uk>写道:
Dave <da**@telco.co.uk> wrote:
我正在尝试将XMl发布到URl但是当我测试它时,请求
流中的文本似乎没有被发送:
//配置安全证书&凭证
req.ClientCertificates.Add(myCert);
req.Credentials = myCache;
//设置HTTP请求标头
req.Method =" POST" ;
req.ProtocolVersion = HttpVersion.Version11;
req.ContentLength = postdata.Length;
I''m trying to post XMl to a URl but when I test it the text in the request
stream doesn''t appear to get sent:
// Configure secure certificate & credentials
req.ClientCertificates.Add(myCert);
req.Credentials = myCache;
// Setup HTTP Request headers
req.Method = "POST";
req.ProtocolVersion=HttpVersion.Version11;
req.ContentLength = postdata.Length;
这行可能是错误的。事实上,我不知道它正在使用什么postdata
变量,因为你不会声明名为
postdata的局部变量,直到稍后。
-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复该群组,请不要给我发邮件
This line is probably the mistake. In fact, I don''t know what postdata
variable it''s using, as you don''t declare the local variable called
postdata until later on.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
啊,该死的 - 那是我把代码撕掉了!
对不起 - 在实际代码postdata行在所有这些代码之前,我只是
在复制代码时把它移到错误的地方。
还有其他想法吗?!
干杯,
Dave
" Jon Skeet [C#MVP]" < SK *** @ pobox.com>在消息中写道
新闻:MP ************************ @ msnews.microsoft.c om ...
Ah, damn - that''s me ripping the code out!
Sorry - in the actual code the postdata line is before all this code, I just
moved it into the wrong place when copying the code.
Any other ideas?!
Cheers,
Dave
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Dave< da ** @ telco.co.uk>写道:
Dave <da**@telco.co.uk> wrote:
我正在尝试将XMl发布到URl但是当我测试它时,
请求流中的文本似乎没有被发送:
//配置安全证书&凭证
req.ClientCertificates.Add(myCert);
req.Credentials = myCache;
//设置HTTP请求标头
req.Method =" POST" ;
req.ProtocolVersion = HttpVersion.Version11;
req.ContentLength = postdata.Length;
I''m trying to post XMl to a URl but when I test it the text in the request stream doesn''t appear to get sent:
// Configure secure certificate & credentials
req.ClientCertificates.Add(myCert);
req.Credentials = myCache;
// Setup HTTP Request headers
req.Method = "POST";
req.ProtocolVersion=HttpVersion.Version11;
req.ContentLength = postdata.Length;
这一行可能是错误的。事实上,我不知道它正在使用什么postdata
变量,因为你直到后来才宣布名为
postdata的局部变量。
- Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复小组,请不要给我发邮件
This line is probably the mistake. In fact, I don''t know what postdata
variable it''s using, as you don''t declare the local variable called
postdata until later on.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
>
Dave< da ** @ telco.co.uk>写道:
Dave <da**@telco.co.uk> wrote:
啊,该死的 - 那是我把代码翻出来的!
抱歉 - 在实际的代码中,postdata行在所有这些代码之前,我只是<复制代码时将它移到了错误的位置。
Ah, damn - that''s me ripping the code out!
Sorry - in the actual code the postdata line is before all this code, I just
moved it into the wrong place when copying the code.
您的XML数据可能包含任何非ASCII字符吗? postdata.Length
是字符长度,但内容长度实际上必须是* b $ b长度*字节*。如果你有任何非ASCII字符,那么他们每次最终会花费超过一个字节,因此你的长度将是错误的。
错误。
(BOM或字节顺序标记,也会影响这一点,但我不认为
你最终会得到任何。)
接收方的请求是什么样的? (从 http://www.pocketsoap.com运行TcpTrace
/ tcptrace / 作为一种代理只是为了看看
请求标题等是什么样的。)
-
Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet
如果回复小组,请不要给我发邮件
Might your XML data have any non-ASCII characters in? postdata.Length
is the length in characters, but the content length really has to be
the length in *bytes*. If you have any non-ASCII characters, they''ll
end up taking more than one byte each, and thus your length will be
wrong.
(BOM, or byte-order markings, would affect this too, but I don''t think
you''ll end up with any.)
What does the request look like on the receiving side? (Run TcpTrace
from http://www.pocketsoap.com/tcptrace/ as a sort of proxy just to see
what the request headers etc are like.)
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
这篇关于XML HTTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!