Webrequest and POST

J

Jay

am trying to call a webservice from C# client.
I am having trouble sending a POST via webrequest.

This is the URL: http://T9946ISP0001:8080/PrintMgr/ProcessRequest.jsp

Here is the method : createSession

The params are :param1=1024

Following is the code snippet - I am not sure how I specify the URL , the
method name and its params..

----------------------------------------------------------------------------
------------------

req.ContentLength = postData.Length;

HttpWebRequest req = (HttpWebRequest)

WebRequest.Create("http://T9946ISP0001:8080/PrintMgr/ProcessRequest.jsp");

req.Method = "POST";


ASCIIEncoding enc = new ASCIIEncoding();

byte[] postData = enc.GetBytes("methodAlias=createSession&param1=1024");

req.ContentLength = postData.Length;

Stream reqStream = req.GetRequestStream();

reqStream.Write(postData, 0, postData.Length);

reqStream.Close();

WebResponse resp = req.GetResponse();
 
J

Joerg Jooss

Jay said:
am trying to call a webservice from C# client.
I am having trouble sending a POST via webrequest.

This is the url: http://T9946ISP0001:8080/PrintMgr/ProcessRequest.jsp

Here is the method : createSession

The params are :param1=1024

Following is the code snippet - I am not sure how I specify the URL ,
the method name and its params..

----------------------------------------------------------------------
------ ------------------

req.ContentLength = postData.Length;

HttpWebRequest req = (HttpWebRequest)

WebRequest.Create("http://T9946ISP0001:8080/PrintMgr/ProcessRequest.js
p");

req.Method = "POST";


ASCIIEncoding enc = new ASCIIEncoding();

byte[] postData =
enc.GetBytes("methodAlias=createSession&param1=1024");

req.ContentLength = postData.Length;

Stream reqStream = req.GetRequestStream();

reqStream.Write(postData, 0, postData.Length);

reqStream.Close();

WebResponse resp = req.GetResponse();

A Web Service deployed as JSP? That doesn't seem right... anyway,
you're code is basically OK, except that you don't set a Content-Type
and that you need to know if that Web Service can be called like that
or if you need to use SOAP as protocol. In the latter case forget about
manually implementing this functionality and use Visual Studio to build
a Web Service client.

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top