使用POST方法发送

使用POST方法发送

本文介绍了如何使用POST方法发送字符串消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的开发人员,
我有String消息和URL.

strmsg ="ABCDEFDYYGYGGY"
Response.Redirect("http://www.teprocess.co.in/Gateway/Request.jsp?msg=" + strMsg);

我发送带有查询字符串的字符串消息,并通过字符串消息strmsg击中上述URL.


但是我想使用POST方法发送此String参数strmsg.
有人告诉我如何在C#中的.cs代码中使用POST方法将字符串参数命中URL.

问候,
Ravi Sharma

Dear Developer,
I have String message and URL.

strmsg = "ABCDEFDYYGYGGY"
Response.Redirect("http://www.teprocess.co.in/Gateway/Request.jsp?msg="+strMsg);

I Send string message with query string and the hit the above URL with String message strmsg .


But i want to Send this String parameter strmsg with the POST Method.
Anybody tell me hows to hit string parameter to URL with POST method in .cs code in c#.

Regards,
Ravi Sharma

推荐答案

string query = "Hello World";

WebRequest myRequest = WebRequest.Create("https://myurl");
myRequest.Timeout = 60000;
myRequest.Method = "POST";
myRequest.ContentLength = query.Length;
myRequest.ContentType = "application/x-www-form-urlencoded";

StreamWriter postWriter = new StreamWriter(myRequest.GetRequestStream());
postWriter.Write(query);
postWriter.Close();



如果您想获得回复,请:



If you want to get a response back then:

WebResponse myResponse = myRequest.GetResponse();
StreamReader rdr = new StreamReader(myResponse.GetResponseStream());




这篇关于如何使用POST方法发送字符串消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 18:16