【问题标题】:Unable to read header information in vb.net web service无法读取 vb.net Web 服务中的标头信息
【发布时间】:2015-10-20 20:32:49
【问题描述】:

我无法读取传递到我的 Web 服务的标头。我正在使用 curl 调用我的 Web 服务,该服务返回没有错误,但传入的标头值为空白。

curl command with return message:
C:\curl>curl -X POST -H "Token: 123" -d '' http://localhost/Service.asm
x/GoCardLessWebHook

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://MyGoCardLessAPI.org/">200 OK - </string>

这是网络服务代码:

Public Class clsSoapHeader
    Inherits SoapHeader
    Public Token As String
End Class



<WebService(Namespace:="http://MyGoCardLessAPI.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
<System.Web.Script.Services.ScriptService()>
Public Class Service

    Inherits System.Web.Services.WebService

    Public GoCardLessHeaders As New clsSoapHeader

    <WebMethod(), _
    SoapHeader("GoCardLessHeaders", Direction:=SoapHeaderDirection.InOut)> _
    Public Function GoCardLessWebHook() As String

        Dim sTemp As String = "Unknown"

        sTemp = GoCardLessHeaders.Token


        Return "200 OK - " & sTemp

    End Function

【问题讨论】:

    标签: vb.net web service asmx


    【解决方案1】:

    我想通了。当我需要读取 http 标头时,代码正在读取肥皂标头。对于任何寻找答案的人来说,这非常简单。在您的网络方法中添加此代码。对于这个例子,我正在寻找标题“令牌”:

    Dim sTemp As String = ""
    
    Dim colHeaders As NameValueCollection
    
    
    ' Load Header collection into NameValueCollection object.
    colHeaders = Context.Request.Headers
    
    sTemp = colHeaders("Token")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-26
      • 1970-01-01
      • 1970-01-01
      • 2011-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多