Click here to Skip to main content
14,836,641 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

Any ideas what I'm doing wrong?

In a console app, I'm doing a POST to an api via .NET VB code.

The URL I create is:

where PARENTNETHANDLE is a valid api value.
APIKEY is a valid api key.

I get a WebException:

Critical error in ExecutePostURLStream. URL: - The remote server returned an error: (404) Not Found. Status: 7. Result: -2146233079. Status Code: NotFound. Status Description : Not Found

I'm able to do GETS to the api just fine.

The XML I create to send along with the URL is:

<?xml version="1.0"?>
-<customer xmlns="">
<customerName>First Name</customerName>
<name>United States</name>
<handle> </handle>
<line number="0">150 Main St #16</line>
<Line number=""> </Line>
<registrationDate> </registrationDate>

Here's the .NET VB function I execute sending in the URL and the XML:

Public Function ExecutePostURLStream(ByRef strURL As String, ByRef strData As String) As Stream

Dim strErrorMessage As String = ""

Dim hwrRequest As HttpWebRequest = DirectCast(WebRequest.Create(strURL), HttpWebRequest)
hwrRequest.Method = "POST"

hwrRequest.ContentType = "application/x-www-form-urlencoded"

hwrRequest.ContentLength = strData.Length

Dim swWriter As New StreamWriter(hwrRequest.GetRequestStream(), System.Text.Encoding.ASCII)

Dim sStream As Stream = hwrRequest.GetResponse().GetResponseStream()

' Return valid value.
Return sStream

Catch ex As WebException

strErrorMessage = "Critical error in ExecutePostURLStream. URL: " & strURL & " - " & ex.Message & " - Status: " & ex.Status & " - Result: " & ex.HResult.ToString()

If ex.Status = WebExceptionStatus.ProtocolError Then
strErrorMessage += " Status Code: " & CType(ex.Response, HttpWebResponse).StatusCode.ToString() & " Status Description : " & CType(ex.Response, HttpWebResponse).StatusDescription.ToString()
End If

End Try

If strErrorMessage <> "" Then
Throw New System.Exception(strErrorMessage)
End If

Return Nothing

End Function

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900