2015-10-20 44 views
1

我無法讀取傳遞到我的Web服務中的標題。我正在使用curl來調用我的web服務,它返回時沒有錯誤,但傳入的標題值爲空。無法讀取vb.net 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> 

這裏是Web服務代碼:

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 

回答

1

我想通了。當我需要閱讀http頭文件時,該代碼正在閱讀soap頭文件。對於尋找答案的人來說,這非常簡單。在你的web方法中添加這段代碼。對於這個例子,我正在尋找標題'令牌':

Dim sTemp As String = "" 

Dim colHeaders As NameValueCollection 


' Load Header collection into NameValueCollection object. 
colHeaders = Context.Request.Headers 

sTemp = colHeaders("Token")