Use Http Post to call Web Service
2016-07-30 13:47
393 查看
[WebMethod]
public bool IsUserExist(string userName) {
if (userName == "raymond")
return true;
else
return false;
}
protected void Button2_Click(object sender, EventArgs e)
{
byte[] data = System.Text.Encoding.ASCII.GetBytes("userName=" + TextBox1.Text);
System.Net.WebRequest request = System.Net.HttpWebRequest.Create(
"http://localhost/samples/MyService.asmx/IsUserExist");
request.Method = "POST";
request.ContentLength = data.Length;
request.ContentType = "application/x-www-form-urlencoded";
System.IO.Stream str = request.GetRequestStream();
str.Write(data, 0, data.Length);
str.Flush();
System.Net.WebResponse response = request.GetResponse();
System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream());
string result = reader.ReadToEnd();
TextBox2.Text = result; // the result here is xml format, you need to handle this
}
相关文章推荐
- How to use JQuery to call a WebService (*.asmx) method?
- How to use HttpWebRequest to post data to another page which is on another server
- How to use HttpURLConnection POST data to web server?
- How to use HttpWebRequest to send POST request to another web server?
- Use VBA to call Web Service
- How to use HttpWebRequest to send POST request to another web server?
- use webHttpBinding to implement WCF Rest Service
- How to use HttpURLConnection POST data to web server?
- Use Webservice Through Primitive XML HTTP Requestion
- Develop an Apache HttpClient client for Android to a JAX-RS web service
- Login to website using HttpWebRequest + AllowAutoRedirect + POST + Going MAD!
- Web service request SetParameters to Report Server http://host/reportserver failed. Error: 请求因 HTTP 状态 401 失败: Unauthorized
- How to use GET and POST methods in HTTP from a MIDlet
- Call web service using HttpWebRequest and serialization
- Flash 9/Flash CS 3 HTTP Post 请求Web Service by .net
- Web service request SetParameters to Report Server http://host/reportserver failed. Error: 请求因 HTTP 状态 401 失败: Unauthorized
- Android HTTP Post WebService
- 如何用JavaScript调用Web服务——callService/useService
- 如何用JavaScript调用Web服务——callService/useService
- JavaScript调用Web服务(callService/useService)