2014-04-03 57 views
1

我試圖用multimechanize測試一個簡單的web服務,但我有一些問題......我想同樣的網址,以及在JMeter的相同的XML,我得到了正確的結果測試香皂Multimechanize

http://www.webservicex.net/globalweather.asmx http://www.webservicex.net/globalweather.asmx?op=GetWeather

這裏是我的Python代碼

進口的urllib2 進口時間

類交易(對象):('/ Users/moisessiles/multimech/gapProject/test_scripts/soap.xml')爲f: self.soap_body = f.read()

def run(self): 
    req = urllib2.Request(url='http://www.webservicex.net/globalweather.asmx', data=self.soap_body) 
    req.add_header('Content-Type', 'application/soap+xml') 
    req.add_header('SOAPAction', 'http://www.webserviceX.NET/GetWeather') 

    start_timer = time.time() 
    resp = urllib2.urlopen(req) 
    content = resp.read() 
    latency = time.time() - start_timer 

    self.custom_timers['Example_SOAP_Msg'] = latency 

    assert (resp.code == 200), 'Bad HTTP Response' 
    #assert ('Data Not Found' in content), 'Failed Content Verification' 

下面是XML

<?xml version="1.0" encoding="utf-8"?> 
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
     <soap:Body> 
     <GetWeather xmlns="http://www.webserviceX.NET"> 
      <CityName>San Jose</CityName> 
      <CountryName>Costa Rica</CountryName> 
     </GetWeather> 
     </soap:Body> 
    </soap:Envelope> 

,這是輸出中

1,0.259,1396560721,USER_GROUP-1,0.253,HTTP錯誤415:不支持的媒體類型,{} 2,0.489,1396560721,user_group-1,0.229,HTTP錯誤415:不支持的介質類型,{} 3,0.721,1396560721,user_group-1,0.232,HTTP錯誤415:不支持的介質類型,{} 4,0.994 ,1396560722,user_group-1,0.228,HTTP錯誤415:不支持的介質類型,{} 5,1.190,1396560722,user_group-1,0.241,HTTP錯誤415:不支持的介質類型,{} 6,1.422,1396560722,user_group -1,0.231,HTTP錯誤415:不支持的媒體類型,{} 7,1.653,1396560722,user_group_1,0.231,HTTP錯誤415:不支持的媒體類型,{} ,8,1.85,1396560723,user_group_1,0.231 ,HTTP錯誤415:不支持的媒體類型,{} 9,2.123,1396560723,user_group-1,0.238,HTTP錯誤415:不支持的媒體類型,{} 10,2.373,1396560723,user_組1,0.249,HTTP錯誤415:不支持的媒體類型,{} 11,2.615,1396560723,user_group-1,0.224,HTTP錯誤415:不支持的媒體類型,{} 12,2.849,1396560724,user_group-1, 0.234,HTTP錯誤415:不支持的媒體類型,{} 13,3.108,1396560724,user_group-1,0.258,HTTP錯誤415:不支持的媒體類型,{} 14,3.359,1396560724,user_group-1,0.251, 415:不支持的媒體類型,{} 15,6.581,1396560727,USER_GROUP-1,3.222,HTTP錯誤415:不支持的媒體類型,{}

分析結果...

交易:15個 錯誤: 15

回答

0

我能夠使用提琴手重現您的問題。 差不多,你從服務器得到一個415個狀態碼:

HTTP/1.1 415 Unsupported Media Type 
Cache-Control: private 
Content-Type: text/html 
Server: Microsoft-IIS/7.0 
X-AspNet-Version: 4.0.30319 
X-Powered-By: ASP.NET 
Date: Sun, 06 Apr 2014 14:57:02 GMT 
Content-Length: 76 

The server cannot service the request because the media type is unsupported. 

這裏的問題是,你正在發送SOAP 1.1有效載荷不支持的內容類型的應用程序/肥皂+ XML。

如果你想解決這個問題,你可以使用SOAP 1。2有效負載:

POST http://www.webservicex.net/globalweather.asmx HTTP/1.1 
Host: www.webservicex.net 
Content-Type: application/soap+xml; charset=utf-8 
Content-Length: 420 
SOAPAction: "http://www.webserviceX.NET/GetWeather" 

<?xml version="1.0" encoding="utf-8"?> 
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope"> 
    <soap12:Body> 
    <GetWeather xmlns="http://www.webserviceX.NET"> 
     <CityName>San Jose</CityName> 
     <CountryName>Costa Rica</CountryName> 
    </GetWeather> 
    </soap12:Body> 
</soap12:Envelope> 

此請求將像魅力一樣工作。但是,Web服務不會爲聖何塞返回數據:)也許對於利比里亞?

不過,如果你仍想發出一個SOAP 1.1信封,然後就改變Content-type頭:這應該工作:

POST http://www.webservicex.net/globalweather.asmx HTTP/1.1 
Content-Type: text/xml; charset=utf-8 
Content-Length: 411 
SOAPAction: "http://www.webserviceX.NET/GetWeather" 
Host: www.webservicex.net 

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <GetWeather xmlns="http://www.webserviceX.NET"> 
     <CityName>Liberia</CityName> 
     <CountryName>Costa Rica</CountryName> 
    </GetWeather> 
    </soap:Body> 
</soap:Envelope> 
+1

酷,我能解決這個問題,謝謝... – msiles

相關問題