我有一些問題,同時發佈xml數據使用HttpWebRequest。其實我想發佈3個表單變量使用.net發佈XML數據與一些字段HttpWebRequest
其中2個用於憑證,第三個用於XML數據到api,api將驗證並處理xml數據,並且如果沒有發現錯誤將返回成功。
這是什麼文檔說。
數據將通過HTTPS FORM帖子傳遞給網關,成功接收數據後將返回字符串值「success」。將發佈三個FORM變量,其中兩個將包含憑據,第三個將包含HR-XML數據。出於任何原因發佈失敗時,將返回字符串值「error」。包含HR-XML訂單(串)
這裏
表單域 integration_field1 = 1234,integration_field2 = 2345pwd,hrxml =表單字段是什麼,我已經編寫..
string strId = "123";
string strName = "test";
StreamReader sr2 = File.OpenText(Server.MapPath("~/App_Data/XMLFile.xml"));
string xml = sr2.ReadToEnd();
sr2.Close();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);
xml = HttpUtility.UrlEncode(xmlDoc.OuterXml);
System.Text.UTF8Encoding encoding = new UTF8Encoding();
string postData = "xmldata=" + xml;
byte[] data = encoding.GetBytes(postData);
// Prepare web request...
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http://localhost:1994/TestXMLPost/PostData.aspx");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
// Send the data.
newStream.Write(data, 0, data.Length);
newStream.Close();
WebResponse res = (HttpWebResponse)myRequest.GetResponse();
StreamReader sr = new StreamReader(res.GetResponseStream());
string str = sr.ReadToEnd();
sr.Close();
在POSTDATA。 aspx,我做了這個測試目的
if (Request.Form.Count > 0)
{
Response.Write(Request.Form["xmldata"] + "");
}
我沒有收到任何迴應。只有錯誤「遠程服務器返回錯誤:(500)內部服務器錯誤。」 這裏是我想模擬使用HttpWebRequest的HTML表單。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>testing</title>
</head>
<body>
<form action="https://myurl.com/samplepage.cfm" method="post" >
integration_id<input type="text" name="integration_id" value="id" /><br />
integration_pwd<input type="text" name="integration_pwd" value="pwd" /><br />
<textarea name="hrxml" style="height: 404px; width: 593px">
<?xml version="1.0" encoding="UTF-8"?>
<BackgroundCheck account="test" userId="test" password="test">
<BackgroundSearchPackage>
<ReferenceId>
<IdValue>12345678</IdValue>
</ReferenceId>
<PersonalData>
<PersonName>
<GivenName>TEST</GivenName>
<FamilyName primary="undefined">TEST</FamilyName>
</PersonName>
<DemographicDetail>
<GovernmentID countryCode="US" issuingAuthority="SSN">00000000000000</GovernmentID>
<DateOfBirth>1901-01-01</DateOfBirth>
</DemographicDetail>
</PersonalData>
</BackgroundSearchPackage>
</BackgroundCheck>
</textarea>
<input type="submit" />
</form>
</body>
</html>
感謝
...和?有什麼問題?你有什麼嘗試? – RPM1984 2010-10-27 08:00:28