How can I Convert httpwebresponse
to httpresponsemessage
in c#?
***var request = (HttpWebRequest)WebRequest.Create(queryUri);
request.Method = "GET";
var response = (HttpWebResponse)request.GetResponse();***
I want to convert this response to Httpresponsemessage
type.
Or is there any way to get the response from HttpWebResponse
?
Based on this StackoverFlow subject , I think this is not possible. HttpResponseMessage is newer than HttpWebResponse (Framework 4.5).
The HttpResponseMessage class definition and the HttpWebResponse class definition do not show any common inheritance, and the way to get content is not compatible : content is a HttpContent type in the first case, and a stream in the second (see Microsoft sample code ).
So you'll probably have to handle both response types, except if you can migrate your code to use only a single one.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.