I originally wanted to use jsonp for cross-origin requests, but sb writes the interface and does not change the return value... I have to request the interface in the background..., jsonpsb
String url = "ssss.com ";
// In the demo, the get request HttpWebResponse w = HttpHelper. createGetHttpResponse (url, 30000, null, null); StreamReader sr = new StreamReader (w. getResponseStream (); string/* This is a Json string */jsonstr = sr. readToEnd ();
Using System; using System. collections. generic; using System. IO; using System. net; using System. net. security; using System. security. cryptography. x509Certificates; using System. text; public class HttpHelper {/// <summary> /// create an HTTP request in GET mode //</summary> /// public static HttpWebResponse CreateGetHttpResponse (string url, int timeout, string userAgent, CookieCollection cookies) {HttpWebRequest request = n Ull; if (url. startsWith ("https", StringComparison. ordinalIgnoreCase) {// verify the validity of the server certificate (a certificate issued by a non-third-party authority, such as a self-generated certificate, without verification, returns true here) ServicePointManager. serverCertificateValidationCallback = new RemoteCertificateValidationCallback (CheckValidationResult); request = WebRequest. create (url) as HttpWebRequest; request. protocolVersion = HttpVersion. version10; // http version. The default value is 1.1. Set this parameter to 1.0} else {request = WebReque. St. create (url) as HttpWebRequest;} request. method = "GET"; // set the proxy UserAgent and timeout // request. userAgent = userAgent; // request. timeout = timeout; if (cookies! = Null) {request. cookieContainer = new CookieContainer (); request. cookieContainer. add (cookies);} return request. getResponse () as HttpWebResponse;} // <summary> // create an HTTP request in POST mode /// </summary> public static HttpWebResponse createpostpresponse (string url, IDictionary <string, string> parameters, int timeout, string userAgent, CookieCollection cookies) {HttpWebRequest request = null; // If sent HTTPS request if (url. startsWith ("https", StringComparison. ordinalIgnoreCase) {// ServicePointManager. serverCertificateValidationCallback = new RemoteCertificateValidationCallback (CheckValidationResult); request = WebRequest. create (url) as HttpWebRequest; // request. protocolVersion = HttpVersion. version10;} else {request = WebRequest. create (url) as HttpWebRequest;} request. method = "POST"; request. co NtentType = "application/x-www-form-urlencoded"; // set the proxy UserAgent and timeout // request. userAgent = userAgent; // request. timeout = timeout; if (cookies! = Null) {request. CookieContainer = new CookieContainer (); request. CookieContainer. Add (cookies) ;}// send POST data if (! (Parameters = null | parameters. count = 0) {StringBuilder buffer = new StringBuilder (); int I = 0; foreach (string key in parameters. keys) {if (I> 0) {buffer. appendFormat ("& {0 }={ 1}", key, parameters [key]);} else {buffer. appendFormat ("{0} = {1}", key, parameters [key]); I ++ ;}} byte [] data = Encoding. ASCII. getBytes (buffer. toString (); using (Stream stream = request. getRequestStream () {stream. write (data, 0, data. length) ;}} string [] values = request. headers. getValues ("Content-Type"); return request. getResponse () as HttpWebResponse;} // <summary> // obtain the request data /// </summary> public static string GetResponseString (HttpWebResponse webresponse) {using (Stream s = webresponse. getResponseStream () {StreamReader reader = new StreamReader (s, Encoding. UTF8); return reader. readToEnd () ;}/// <summary> // verify the certificate /// </summary> private static bool CheckValidationResult (object sender, X509Certificate certificate, X509Chain chain, sslPolicyErrors errors) {if (errors = SslPolicyErrors. none) return true; return false ;}}