远程服务器返回错误:(500)httprequest上的内部服务器错误

时间:2013-01-18 18:41:53

标签: xml vb.net soap httprequest

家伙我正在使用api,我必须使用soap请求向服务器xml发送请求,但服务器显示以下错误:远程服务器返回错误:(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())

3 个答案:

答案 0 :(得分:1)

HTTP错误代码500,正如它所说,是一个内部服务器错误。您的联系人可能需要查看他的日志并报告错误是什么,因为它是在他的结束而不是你的。

如果您的请求格式与其预期格式不匹配并引发错误,则需要在其结束时正确处理,而不是报告错误500.

所以....基本上它不在你的手中。

答案 1 :(得分:0)

获取窗口的应用程序日志会很有帮助。 转到开始 - &gt;跑 - &gt;事件查看器(单击输入) - &gt; Windows日志 - &gt;应用程序 - &gt;检查日志。 有关详细信息,请参阅http://support.microsoft.com/kb/308427。要么 http://www.dotnetnoob.com/2012/03/iis-500-errors-leave-clues-in-log.html

答案 2 :(得分: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()

由于

Umaji Mogre