. NET sends requests, carrying JSON data

Source: Internet
Author: User

<summary>
Send Request
</summary>
<param name= "Uri" > Request address </param>
<param name= "jsonstr" >json data </param>
<returns></returns>
public static string Clientrequest (String Uri, String jsonstr)
{
Try
{
string serviceaddress = Uri;
var HttpRequest = (HttpWebRequest) httpwebrequest.create (serviceaddress);
Httprequest.method = "POST";
Httprequest.contenttype = "Application/json";
Httprequest.proxy = null;
Httprequest.useragent = "mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) gecko/20100101 firefox/11.0 ";
Httprequest.useragent = "mozilla/5.0 (Windows; U Windows NT 6.1; ZH-CN; rv:1.9.2.13) gecko/20101203 firefox/3.6.13 ";
HTTPREQUEST.HEADERS.ADD ("Accept-language", "zh-cn,en-us;q=0.8,zh-hk;q=0.6,ja;q=0.4,zh;q=0.2");
httprequest.accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
Servicepointmanager.servercertificatevalidationcallback = delegate {return true;};
Servicepointmanager.securityprotocol = SECURITYPROTOCOLTYPE.SSL3;
using (var dataStream = new StreamWriter (Httprequest.getrequeststream ()))
{
Datastream.write (JSONSTR);
Datastream.flush ();
Datastream.close ();
}

var HttpResponse = (HttpWebResponse) httprequest.getresponse ();
using (var dataStream = new StreamReader (Httpresponse.getresponsestream ()))
{
var result = Datastream.readtoend ();
return result;
}
}
catch (Exception ex)
{
Return "{\" error\ ": \" "+ Ex. Message + "\"} ";
}
}

. NET sends requests, carrying JSON data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.