Home > Net >  Call the HTTP service computer blue screen
Call the HTTP service computer blue screen

Time:09-24

Call the HTTP framework. The.net framework 4.5.1 calls demo framework. The.net framework 4.5.1 and 4.5.2 tried or blue screen

Use soapUI and posmain tool test without blue screen, bosses have encountered this kind of situation to help see this week thank you

The calling code is as follows: a code:
"[//Logger.Net.Info (${Prefix}] [{name}] [{I}] send content: {sendAsJson}");
Byte [] byteArray containing=encoding. GetBytes (sendAsJson);
HttpWebRequest webReq=(HttpWebRequest) WebRequest. Create (new Uri ($" {string. The Format (" http://10.1.13.103:11100/Pay/")} {the req. Service} "));
WebReq. Method="POST";
WebReq. ContentType="application/x - WWW - form - urlencoded;";
WebReq. Timeout=60 * 1000 * 2;
Var watch=a Stopwatch. StartNew ();
WebReq. ContentLength=byteArray containing. Length;
The Stream newStream=webReq. GetRequestStream ();
NewStream. Write (byteArray containing, 0, byteArray containing. Length);
NewStream. Close ();
HttpWebResponse response=(HttpWebResponse) webReq. The method GetResponse ();
StreamReader sr=new StreamReader (response. GetResponseStream ());
Ret.=the sr ReadToEnd ();
The sr. The Close ();
The response. The Close ();
NewStream. Close ();
Var time=watch. ElapsedMilliseconds;
"[//Logger.Net.Info (${Prefix}] [{name}] [{I}] time-consuming: {time} milliseconds to receive content: {ret}");

Var res=JsonConvert. DeserializeObject (ret);
return res;




Code 2: using (var client=new HttpClient ())
{
Client. The Timeout=new TimeSpan (0, 2, 0);
Try
{
DictionQuery=the req. GetParams ();
Var watch=a Stopwatch. StartNew ();
Var kvcontent=string. Join (" & amp;" , dictionQuery. Select (p=& gt; "${p.K ey}={HttpUtility. UrlEncode (p.V alue)}"));
"[//Logger.Net.Info (${Prefix}] [{name}] [{I}] send assembly content: {kvcontent}");
HttpContent formContent=new FormUrlEncodedContent (dictionQuery);


Url=new Uri (${string. "Format (" http://10.1.13.103:11100/Pay/")} {the req. Service} ");
Var task=client. PostAsync (Url, formContent);
Var response=task. The Result;
Var text=response. Content. ReadAsStringAsync (). The Result;
Watch. Stop ();
Var time=watch. ElapsedMilliseconds;
String logres=text;

"[//Logger.Net.Info (${Prefix}] [{name}] [{I}] time-consuming: {time} milliseconds to receive content: {logres}");
If (the response StatusCode!=HttpStatusCode. OK)
{
Return new TRes
{
Code=4,
Msg=${(int) response. "StatusCode}, {response. StatusCode}"
};
}
If (string. IsNullOrWhiteSpace (text))
{
Return new TRes
{
Code=4,
Msg=$" interface [{name}] gateway abnormal returns the content! Null
"};
}
Var res=JsonConvert. DeserializeObject (text);
return res;
}
The catch (AggregateException ex)
{
Var exceptionDescription=PrintAggregateException (ex, out var mainException);
"[//Logger.Net.Error (${Prefix}] [{name}] [{I}] abnormal content: {exceptionDescription}");
Return new TRes
{
Code=4,
Msg=BuilNiceErrorMsg (mainException)
};
}
The catch (Exception ex)
{
"[//Logger.Net.Error (${Prefix}] [{name}] [{I}] abnormal content: {ex. Message} \ r \ n {ex. StackTrace}");
Return new TRes
{
Code=2,
Msg=BuilNiceErrorMsg (ex. Message)
};
}
}



Bosses look a little help

CodePudding user response:

Don't sink, bosses for answers

CodePudding user response:

Bosses look down thank you for your help!

CodePudding user response:

Don't see the problem, it is recommended that do subtraction,

We don't think, what HTTP is problem, we think that is a place where other questions

So my advice is to do subtraction, write a console, separate the console, what all don't write, just pure HTTP part, if the console is an error in to ask
If the console is not an error, check your spare parts and other interactive program with you

CodePudding user response:

I always think, blue screen and HTTP has nothing to do,
Should still have relations and leak memory,
You try, just the most simple helloworld interface, call and see if you have any questions,
  •  Tags:  
  • C #
  • Related