1

ソープリクエストを使用してサーバーxmlベースにリクエストを送信する必要があるAPIに取り組んでいますが、サーバーは次のエラーを表示しています:リモートサーバーがエラーを返しました:(500)内部サーバーエラー、助けていただければ幸いです

私のコードは次のようなものです:

   Dim s = ""
    s = s & "<?xml version=""1.0"" encoding=""UTF-8""?>" & vbCrLf

    s = s & "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">" & vbCrLf

    s = s & "<soapenv:Body>" & vbCrLf

    s = s & "<OTA_AirLowFareSearchRQ EchoToken=""0"" SequenceNmbr=""0"" TransactionIdentifier=""0"" AvailableFlightsOnly="""" DirectFlightsOnly="""" xmlns=""http://www.opentravel.org/OTA/2003/05"">" & vbCrLf
    s = s & "<POS xmlns=""http://www.opentravel.org/OTA/2003/05"">" & vbCrLf
    s = s & "<Source AgentSine="""" PseudoCityCode="""" TerminalID=""1"">" & vbCrLf
    s = s & "<RequestorID ID=""AFFILIATE""/>" & vbCrLf
    s = s & "</Source>" & vbCrLf



    s = s & "<YatraRequests>" & vbCrLf
    s = s & "<YatraRequest DoNotHitCache=""false"" DoNotCache=""false"" YatraRequestTypeCode=""SMPA"" Description="""" MidOfficeAgentID=""28737"" AffiliateID=""TRAVELPARTNER"" />" & vbCrLf
    s = s & "</YatraRequests>" & vbCrLf
    s = s & "</POS>" & vbCrLf
    s = s & "<TravelerInfoSummary>" & vbCrLf
    s = s & "<AirTravelerAvail>" & vbCrLf
    s = s & "<PassengerTypeQuantity Code=""ADT"" Quantity=""" & drAdult.SelectedValue & """/>" & vbCrLf
    s = s & "<PassengerTypeQuantity Code=""CHD"" Quantity=""" & drpChil.SelectedValue & """/>" & vbCrLf
    s = s & "<PassengerTypeQuantity Code=""INF"" Quantity=""" & drpInfant.SelectedValue & """/>" & vbCrLf

    s = s & "</AirTravelerAvail>" & vbCrLf
    s = s & "</TravelerInfoSummary>" & vbCrLf
    s = s & "<SpecificFlightInfo>" & vbCrLf
    s = s & "<Airline Code=""""/>" & vbCrLf
    s = s & "</SpecificFlightInfo>" & vbCrLf
    s = s & "<OriginDestinationInformation>" & vbCrLf
    s = s & "<DepartureDateTime>" & txtDeparture.Text & "</DepartureDateTime>" & vbCrLf
    s = s & "<OriginLocation CodeContext=""IATA"" LocationCode=""" & drpFrom.SelectedValue & """>" & drpFrom.SelectedValue & "</OriginLocation>" & vbCrLf
    s = s & "<DestinationLocation CodeContext=""IATA"" LocationCode=""" & drpTo.SelectedValue & """>" & drpTo.SelectedValue & "</DestinationLocation>" & vbCrLf
    s = s & "</OriginDestinationInformation>" & vbCrLf
    s = s & "<TravelPreferences>" & vbCrLf
    s = s & "<VendorPref Code=""SG""/>" & vbCrLf
    s = s & "<VendorPref Code=""DN""/>" & vbCrLf
    s = s & "<CabinPref Cabin=""" & drpClass.SelectedValue & """/>" & vbCrLf
    s = s & "</TravelPreferences>" & vbCrLf
    s = s & "</OTA_AirLowFareSearchRQ>" & vbCrLf
    s = s & "</soapenv:Body>" & vbCrLf
    s = s & "</soapenv:Envelope>" & vbCrLf

    Dim url = "http://203.189.91.127:9090/services/spm/spm"

    Dim doc As New XmlDocument()

    doc.LoadXml(s)

    Dim req As HttpWebRequest = WebRequest.Create(url)
    req.Headers.Add("SOAPAction", "")

    req.ContentType = "text/xml;charset=""utf-8"""
    req.Accept = "text/xml"
    req.Method = "POST"
    Dim stm As Stream = req.GetRequestStream()
    doc.Save(stm)
    stm.Close()
    Dim resp As WebResponse = req.GetResponse()
    stm = resp.GetResponseStream()
    Dim r As StreamReader = New StreamReader(stm)
    'process SOAP return doc here. For now, we'll just send the XML out to the browser ...
    Response.Write(r.ReadToEnd())
4

3 に答える 3

1

HTTPエラーコード500は、それが言うように、内部サーバーエラーです。連絡先はおそらく彼のログを表示し、エラーがあなたの側ではなく彼の側にあるため、エラーが何であるかを報告する必要があります。

リクエストの形式が予想される形式と一致せず、エラーが発生する可能性がある場合は、エラー500を報告するのではなく、リクエストの形式を適切に処理する必要があります。

だから....基本的にあなたの手から。

于 2013-01-18T18:44:58.140 に答える
0

最初にこのことをコメントしてください

's = ?xml version=""1.0"" encoding=""UTF-8""?"

次に、このコードを追加して、問題なく動作するようにします

        Dim Parameters As String = GetRq()
        Dim request As WebRequest = WebRequest.Create(url)
        request.Credentials = CredentialCache.DefaultNetworkCredentials
        request.ContentType = "application/x-www-form-urlencoded"
        request.Method = "POST"
        request.Headers.Add("SOAPAction", url)
        Dim byteArray As Byte() = Encoding.UTF8.GetBytes(Parameters)
        request.ContentType = "text/xml"

        request.ContentLength = byteArray.Length

        Dim dataStream As Stream = request.GetRequestStream()
        dataStream.Write(byteArray, 0, byteArray.Length)
        dataStream.Close()

        Dim response As WebResponse = request.GetResponse()
        dataStream = response.GetResponseStream()

        Dim reader As New StreamReader(dataStream)
        Dim responseFromServer As String = reader.ReadToEnd()

        reader.Close()
        dataStream.Close()
        response.Close()

ありがとう

馬路もぐれ

于 2014-06-11T10:16:53.690 に答える
0

ウィンドウのアプリケーション ログを取得すると役立ちます。[スタート] -> [実行] -> [イベント ビューアー] (Enter をクリック) -> [Windows ログ] -> [アプリケーション] -> [ログの確認] に移動します。詳細については、 http://support.microsoft.com/kb/308427を参照してください。または http://www.dotnetnoob.com/2012/03/iis-500-errors-leave-clues-in-log.html

于 2013-01-19T09:46:39.647 に答える