Solved

ASP.NET/VB: Get Result Returned by HttpWebRequest

Posted on 2013-12-18
1
503 Views
Last Modified: 2013-12-18
I use the following code to post data to a remote website.  How can I get and output the response from the remote website?
<%@ Page Language="VB"%>
<%@Import namespace="System"%>
<%@Import namespace="System.Web"%>
<%@Import namespace="System.Net"%>
<%@Import namespace="System.IO"%>
<%@Import namespace="System.Text"%>
<%

Dim data as String = "{}"
Dim webRequest As HttpWebRequest = TryCast(WebRequest.Create("http://example.com/"), HttpWebRequest)
webRequest.Method = "POST"
webRequest.ContentType = "application/json"
webRequest.ContentLength = data.Length
webRequest.Accept = "application/json"
webRequest.ReadWriteTimeout = 500000
Dim requestWriter As New StreamWriter(webRequest.GetRequestStream())
requestWriter.Write(data)
requestWriter.Close()


HttpContext.Current.Response.Write("I want the result output here")

%>

Open in new window

0
Comment
Question by:hankknight
1 Comment
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
Comment Utility
You need to call the GetResponse() method of your request to get the stream with the response data in, and then read the result from that.

You can use the sample here as a guide: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.getresponse(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now