不久之前,我已经为我的日常使用创建了一个小型iPhone应用程序。现在我想在使用C#和Compact Framework时将此应用移植到Windows Mobile设备。但我真的不知道如何使用HttpWebRequest,MSDN也不帮助我。我认为我对Web请求如何工作有一定的了解。在Compact Framework项目上需要HttpWebRequest帮助
在iPhone应用程序,我有以下行代码:
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://xxx:[email protected]/RPC2"]];
[theRequest setHTTPMethod:@"POST"];
[theRequest addValue:@"text/xml" forHTTPHeaderField:@"content-type"];
[theRequest setCachePolicy:NSURLCacheStorageNotAllowed];
[theRequest setTimeoutInterval:5.0];
NSString* pStr = [[NSString alloc] initWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodCall><methodName>xxx.SessionInitiate</methodName><params><param><value><struct><member><name>LocalUri</name><value><string></string></value></member><member><name>RemoteUri</name><value><string>xxxx</string></value></member><member><name>TOS</name><value><string>text</string></value></member><member><name>Content</name><value><string>%@</string></value></member><member><name>Schedule</name><value><string></string></value></member></struct></value></param></params></methodCall>", number.text, TextView.text];
NSData* pBody = [pStr dataUsingEncoding:NSUTF8StringEncoding];
[theRequest setHTTPBody:pBody];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
web服务没有WSDL,所以我必须使用的.Net CF的HttpWebRquest对象 我没有得到的是,在哪里把Body(长XML)放在我的请求中?
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(@"https://xxx:[email protected]/RPC2");
req.Method = @"POST";
req.ContentType = @"test/xml";
req.Timeout = 5;
我开始这样,第一行是it's自己HttpWebRequest和对XML的身体我必须创建anotherone?我如何正确使用它,我如何发送它?对不起,如果这可能非常容易,但我真的不明白。我搜索了网络,2本书和msdn,但在每个教程中只有一个带有URL但没有正文的Webrequest。
谢谢
twickl
如果流是在使用,它应该得到冲洗,并在它的一端封闭。 – Jerther 2014-07-22 15:51:39