我正在尝试将XML文档发送到页面.asp,并得到答案,但我得到了以下错误:
System.UriFormatException:无效URI: URI方案无效。在GNS_ZalkarBank.GNSTaskServiceZalkarBank.CreateRequest(String requestData的System.Uri.CreateThis(String uri,Boolean,UriKind uriKind)的System.Net.WebRequest.Create(String requestUriString),在Task.RegistryTemplate.RegistryTaskTemplate.execute(DataSet& requestString的String address( String address),在Task.RegistryTemplate.RegistryTaskTemplate.execute(DataSet&dataSet的GNS_ZalkarBank.GNSTaskServiceZalkarBank.processData(TaskInfo& taskInfo,Object& data)的System.Uri.CreateThis(String address)
我使用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
%>出什么事了?
发布于 2012-09-07 10:21:39
提供的错误文本来自这里:
private HttpWebRequest CreateRequest(string requestData, string address)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(address); // <- THIS LINE
...
}错误描述是抱怨地址https://myadress/osmp_gni_xml.asp无效,https是最可能的原因是连接问题。
尝试通过https进行连接,但一开始就没有安装https服务器端是非常常见的:验证地址是可访问的,安全是正确设置的,以及排序。控制台工具( F12 developer console (IE9的一部分)、FireBug (火狐扩展)或Fiddler (桌面应用程序))是了解外部连接发生什么的最好工具。
发布于 2012-09-07 13:22:17
我怀疑您提供的代码不是有问题的代码,请参见:
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;
}您将地址传递给该方法,但在第一行上将其硬布线。问题在于地址的格式,但这段代码可能不存在。
可能发生的情况是,您从文件或数据库中读取地址,而作为一个人,您看到的是"xml.asp“,因为您使用的是一种有缺陷的无转义机制,但是代码所看到的内容如下:
https/:////myaddress//osmp_gni_xml.asp给出了同样的错误。
在实际代码中,在用SendRequest重写地址的地方,地址的确切值是多少?
https://stackoverflow.com/questions/12313887
复制相似问题