I’m trying send XML document to a page .asp, and get the answer, but I get following error:
System.UriFormatException: Invalid URI: The URI scheme is not valid. at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind) at System.Net.WebRequest.Create(String requestUriString) at GNS_ZalkarBank.GNSTaskServiceZalkarBank.CreateRequest(String requestData, String address) at GNS_ZalkarBank.GNSTaskServiceZalkarBank.SendRequest(String requestString, String address) at GNS_ZalkarBank.GNSTaskServiceZalkarBank.processData(TaskInfo& taskInfo, Object& data) at Task.RegistryTemplate.RegistryTaskTemplate.execute(DataSet& dataSet)`
I implemented a method for sending data to a page with asp server script:
private string SendRequest(String requestString, String address)
{
address = "https://myadress/osmp_gni_xml.asp";
HttpWebRequest httpRequest = this.CreateRequest(requestString, address);
string response = GetResponse(httpRequest);
return response;
}
private HttpWebRequest CreateRequest(string requestData, string address)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address);
request.Method = "POST";
//request.UserAgent = "Test";
byte[] data = Encoding.UTF8.GetBytes(requestData);
request.ContentType = "text/xml; encoding='utf-8'";
request.ContentLength = data.Length;
using (Stream dataStream = request.GetRequestStream())
{
dataStream.Write(data, 0, data.Length);
dataStream.Close();
}
return request;
}
private string GetResponse(HttpWebRequest httpWebRequest)
{
string responseString;
HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse();
using (Stream dataStream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(dataStream))
{
responseString = reader.ReadToEnd();
}
}
return responseString;
}
Server side (script page: osmp_gni_xml.asp):
<%@ Language=VBScript CODEPAGE="65001"%>
<%
Sub AddSubNode(Parent, Name, Value)
Set subNode = XMLDoc.createElement(Name)
Parent.appendChild(subNode)
subNode.appendChild(XMLDoc.createTextNode(Value))
End Sub
Function Stream_BinaryToString(Binary, CharSet)
Const adTypeText = 2
Const adTypeBinary = 1
'Create Stream object
Dim BinaryStream 'As New Stream
Set BinaryStream = CreateObject("ADODB.Stream")
'Specify stream type - we want To save text/string data.
BinaryStream.Type = adTypeBinary
'Open the stream And write text/string data To the object
BinaryStream.Open
BinaryStream.Write Binary
'Change stream type To binary
BinaryStream.Position = 0
BinaryStream.Type = adTypeText
'Specify charset For the source text (unicode) data.
If Len(CharSet) > 0 Then
BinaryStream.CharSet = CharSet
Else
BinaryStream.CharSet = "us-ascii"
End If
'Open the stream And get binary data from the object
Stream_BinaryToString = BinaryStream.ReadText
End Function
result=300
OK="incomplete request"
Dim PostData
Dim biData
PostData = ""
If Request.TotalBytes>0 Then
biData = Request.BinaryRead(Request.TotalBytes)
PostData=Stream_BinaryToString(biData, "utf-8")
ProvStr = "Provider=sqloledb;Data Source=TEST;Initial Catalog=TESTOsmp;User Id=tests_osmp;Password=tests;"
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ProvStr
Set cmdUA = Server.CreateObject("ADODB.Command")
cmdUA.ActiveConnection = Conn
cmdUA.CommandText = "GNI_Import"
cmdUA.CommandType = 4
cmdUA.Parameters.Append cmdUA.CreateParameter("Reestr", 202, 1, 2000, PostData)
Set RS = cmdUA.Execute
result = RS("result")
RS.Close
Conn.Close
Set Conn = Nothing
Set RS = Nothing
End If
'Create XML
Set XMLDoc = Server.CreateObject("Microsoft.XMLDOM")
Set pi = XMLDoc.createProcessingInstruction("xml"," version=""1.0"" encoding=""utf-8""")
XMLDoc.appendChild(pi)
'Main
Set mainNode = XMLDoc.createElement("response")
XMLDoc.appendChild(mainNode)
If result=0 Then
OK="Ok"
Else
result=300
OK="incomplete request"
End If
AddSubNode mainNode, "result", result
AddSubNode mainNode, "comment", OK
Response.ContentType = "text/xml"
Response.Write XMLDoc.XML
Set mainNode = Nothing
Set XMLDoc = Nothing
%>
Whats wrong?
The provided error text comes from here:
The error description is complaining that the address
https://myadress/osmp_gni_xml.aspis invalid, beinghttpsthe most likely causes are connection issues.Trying to connect via
httpsbut not having setuphttpsserver-side in the first place is very common: verify the address is reachable, security is properly setup, and the sort. A console tool like F12 developer console (part of IE9), FireBug (Firefox extension) or Fiddler (desktop application) are the best tools to find out what’s happening when it comes to external connections.