Home > Net >  Using c # to replace HttpEntity in Java?
Using c # to replace HttpEntity in Java?

Time:11-10

I want to use winform procedure calls a web API interface
Write to call Java example:
Form. The add (" file ", fileSystemResource);
Form. The add (" count ", IdUtil simpleUUID ());
HttpEntity Files=new HttpEntity<> (form, headers);
ResponseEntity ResponseEntity=restTemplate. PostForEntity (url, files, the Result. The class).
I search on the Internet, didn't see in c #, with what to replace the HttpEntity, ask everybody to help me

CodePudding user response:

HttpWebRequest and HttpWebResponse

CodePudding user response:

Like those httpclient

CodePudding user response:

You look at the following c # Post data

Public static async Task APIPost (url string, the string data)
{
The string result=string. The Empty;
//set HttpClientHandler AutomaticDecompression
(1) {var handler=new HttpClientHandler AutomaticDecompression=DecompressionMethods. GZip};
//create the HttpClient (note that the incoming HttpClientHandler)
Using HTTP=new HttpClient (var (handler))
{
//using FormUrlEncodedContent do HttpContent
var content=new FormUrlEncodedContent (new Dictionary ()
{
//pass a single value
{" ", the data}//keys must be empty
//transfer object
//{" name ", "hello"},
//{" age ", "16"}
});

//await an asynchronous response to
var response=HTTP. Await PostAsync (url, the content);
//to ensure the success of the HTTP status value
The response. EnsureSuccessStatusCode ();
//await asynchronous read last JSON (note that the gzip automatically extract had been made, and because of the above AutomaticDecompression=DecompressionMethods. Gzip)
Result=await the response. The content. ReadAsStringAsync ();
}
return result;
}
  • Related