我試圖發送XML文檔到頁面的.asp,並得到了答案,但我得到以下錯誤:發送一個網頁,腳本
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)`
我實現了一個方法,用於發送數據到一個頁面與ASP服務器腳本:
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;
}
服務器端(腳本頁面: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
%>
怎麼啦?
是的,你說得對的地方精確值,問題的URL地址。服務器使用https - 我沒有意識到。我只是要求客戶證書。 – Max