2010-10-27 20 views
0

我有一些問題,同時發佈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> 

感謝

+0

...和?有什麼問題?你有什麼嘗試? – RPM1984 2010-10-27 08:00:28

回答

0

使用fiddler,看看有什麼實際發生過線。

另外寫一個你發送到磁盤的副本。

除上述之外,您還可以檢查目標計算機的事件查看器以查找與該錯誤相關的條目(如果您沒有任何替代的錯誤日誌記錄)。

底線是你需要看看發生了什麼。

+0

感謝您的建議。它真的幫助我。我去看看事件查看器,並驚訝地發現xml數據發佈的頁面,抱怨潛在的危險請求請求。我們都知道,Asp.net頁面驗證每個傳入的請求。所以當我設置頁面屬性ValidateRequest =「false」。現在問題已解決。謝謝budy ... :) – 2010-10-29 12:03:58