使用HttpWebRequest类 [英] Using the HttpWebRequest class

查看:149
本文介绍了使用HttpWebRequest类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实例化HttpWebRequest对象:

I instantiate the HttpWebRequest object:

HttpWebRequest httpWebRequest = 
    WebRequest.Create("http://game.stop.com/webservice/services/gameup")
    as HttpWebRequest;

当我邮报的数据,该服务,如何服务哪些网络方法将数据提交给?

When I "post" the data to this service, how does the service know which web method to submit the data to?

我没有code此Web服务,我所知道的是,它是用Java编写的。

I do not have the code to this web service, all I know is that it was written in Java.

推荐答案

这变得有点复杂,但它是完全可行的。

This gets a bit complicated but it's perfectly doable.

您必须知道你想坐的SOAPAction。如果不这样做,你不能提出这项要求。如果你不想手动设置这个,你就可以添加一个服务引用到Visual Studio,但你需要知道服务端点。

You have to know the SOAPAction you want to take. If you don't you can't make the request. If you don't want to set this up manually you can add a service reference to Visual Studio but you will need to know the services endpoint.

在code以下是手动SOAP请求。

The code below is for a manual SOAP request.

// load that XML that you want to post
// it doesn't have to load from an XML doc, this is just
// how we do it
XmlDocument doc = new XmlDocument();
doc.Load( Server.MapPath( "some_file.xml" ) );

// create the request to your URL
HttpWebRequest request = (HttpWebRequest)WebRequest.Create( Your URL );

// add the headers
// the SOAPACtion determines what action the web service should use
// YOU MUST KNOW THIS and SET IT HERE
request.Headers.Add( "SOAPAction", YOUR SOAP ACTION );

// set the request type
// we user utf-8 but set the content type here
request.ContentType = "text/xml;charset=\"utf-8\"";
request.Accept = "text/xml";
request.Method = "POST";

// add our body to the request
Stream stream = request.GetRequestStream();
doc.Save( stream );
stream.Close();

// get the response back
using( HttpWebResponse response = (HttpWebResponse)request.GetResponse() )
{
     // do something with the response here
}//end using

这篇关于使用HttpWebRequest类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆