compbrat75
07-07-2011, 02:13 PM
I'm running in circles.
I'm using ASP.NET 2.0 VB.NET...
All I want to do is take an incoming JSON and send it to Response.Write() so it displays as a text string.
I don't want to parse it or deserialize it. The string is being passed to a mainframe and it's expected a text string.
I keep getting a 400 Bad Request.
Here's the latest code snippet...
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="utf-8" aspcompat="true" Debug="true" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace= "System.Web.Extensions" %>
<%@ Import Namespace="System.Web.Script.Serialization" %>
<%
Dim pgRequest As System.Net.WebRequest
Dim pgResponse As System.Net.WebResponse
Dim buffer() As Byte
Dim iBytesToRead As Integer
Dim iBytesRead As Integer
Dim n As Integer
Dim t As System.IO.Stream
Dim URL = Request.QueryString("url")
pgRequest = System.Net.WebRequest.Create(URL)
pgResponse = pgRequest.GetResponse()
Dim pgStream As StreamReader = new StreamReader(pgResponse.GetResponseStream())
Dim pgString As String
t = pgResponse.GetResponseStream()
iBytesToRead = pgResponse.ContentLength
ReDim buffer(iBytesToRead)
iBytesRead = 0
While iBytesToRead > 0
n = t.Read(buffer, iBytesRead, iBytesToRead)
If n = 0 Then
Exit While
End If
iBytesRead += n
iBytesToRead -= n
End While
Response.Write(buffer)
t.Close()
pgResponse.Close()
%>
Here's the error:
The remote server returned an error: (400) Bad Request.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The remote server returned an error: (400) Bad Request.
Source Error:
Line 21: pgResponse = pgRequest.GetResponse()
Any help would be appreciated!
I'm using ASP.NET 2.0 VB.NET...
All I want to do is take an incoming JSON and send it to Response.Write() so it displays as a text string.
I don't want to parse it or deserialize it. The string is being passed to a mainframe and it's expected a text string.
I keep getting a 400 Bad Request.
Here's the latest code snippet...
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="utf-8" aspcompat="true" Debug="true" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Text" %>
<%@ Import Namespace= "System.Web.Extensions" %>
<%@ Import Namespace="System.Web.Script.Serialization" %>
<%
Dim pgRequest As System.Net.WebRequest
Dim pgResponse As System.Net.WebResponse
Dim buffer() As Byte
Dim iBytesToRead As Integer
Dim iBytesRead As Integer
Dim n As Integer
Dim t As System.IO.Stream
Dim URL = Request.QueryString("url")
pgRequest = System.Net.WebRequest.Create(URL)
pgResponse = pgRequest.GetResponse()
Dim pgStream As StreamReader = new StreamReader(pgResponse.GetResponseStream())
Dim pgString As String
t = pgResponse.GetResponseStream()
iBytesToRead = pgResponse.ContentLength
ReDim buffer(iBytesToRead)
iBytesRead = 0
While iBytesToRead > 0
n = t.Read(buffer, iBytesRead, iBytesToRead)
If n = 0 Then
Exit While
End If
iBytesRead += n
iBytesToRead -= n
End While
Response.Write(buffer)
t.Close()
pgResponse.Close()
%>
Here's the error:
The remote server returned an error: (400) Bad Request.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.WebException: The remote server returned an error: (400) Bad Request.
Source Error:
Line 21: pgResponse = pgRequest.GetResponse()
Any help would be appreciated!