Hello! I need to send a request to a third-party site using a specific link and get a json result. What means can this be done on asp.net mvc? Any examples?
2 answers
public MyObject GetMyObject(string url) { HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Method = "POST"; webRequest.ContentType = "application/json; charset=utf-8"; HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse(); Stream responseStream = webResponse.GetResponseStream(); DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(typeof(MyObject)); MyObject someone = (MyObject)jsonSerializer.ReadObject(responseStream); return someone; }
- Here is the answer :) Thank you! - Eriendel
|
If I understood correctly: a request can be sent and received a response with an HTTP
packet, using, for example, sockets. The response will be the HTTP
package, that is, the HTTP
headers and the html page itself ... Handle and store in Json
format.
- Is there no easier way? An example library simplifies this. - Eriendel
|