Reputation: 1525
I would like to call a post request that would return an http response that should be rendered by the browser. My attempt led to the browser displaying text value system.web.httpwebresponse
var webrequest = WebRequest.Create("URL");
webrequest.Method = "POST";
string postData = "test=1&test2=2";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
webrequest.ContentType = "application/x-www-form-urlencoded";
webrequest.ContentLength = byteArray.Length;
Stream dataStream = webrequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length); WebProxy myProxy = new WebProxy();
Uri newUri = new Uri("http://proxy");
// Associate the newUri object to 'myProxy' object so that new myProxy settings can be set.
myProxy.Address = newUri;
// Create a NetworkCredential object and associate it with the
myProxy.Credentials = new NetworkCredential("user", "pass");
webrequest.Proxy = myProxy;
var resp = webrequest.GetResponse();
return resp;
Upvotes: 1
Views: 1167
Reputation: 190945
You could return the stream as a File
response.
return File(resp.GetResponseStream(), resp.ContentType);
Upvotes: 1
Reputation: 2525
if your result is text, then you could
return Content(new StreamReader(resp.GetResponseStream()).ReadToEnd(), resp.ContentType)
Upvotes: 1