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:
Hi,

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:

https://reg.ote.arin.net/rest/net/PARENTNETHANDLE/customer?apikey=APIKEY

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

I get a WebException:

Critical error in ExecutePostURLStream. URL: https://reg.ote.arin.net/rest/net/PARENTNETHANDLE/customer?apikey=APIKEY - 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="http://www.arin.net/regrws/core/v1">
<customerName>First Name</customerName>
-<iso3166-1>
<name>United States</name>
<code2>US</code2>
<code3>USA</code3>
<e164>1</e164>
</iso3166-1>
<handle> </handle>
-<streetAddress>
<line number="0">150 Main St #16</line>
</streetAddress>
<city>Greenwich</city>
<iso3166-2>CT</iso3166-2>
<postalCode>06830</postalCode>
-<comment>
<Line number=""> </Line>
</comment>
<parentOrgHandle>RL-###</parentOrgHandle>
<registrationDate> </registrationDate>
<privateCustomer>false</privateCustomer>
</customer>

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 = ""

Try
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)
swWriter.Write(strData)
swWriter.Close()

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
Posted

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