Jmeter - How to send XML request to a server?

2019-08-04 09:12发布

I have a HTTP Request Sampler in my test plan. I have given my server name or IP, port and url. I chose the Body Data tab and gave an XML request in this way:

<Request>
    <Header><Log><Level>None</Level></Log></Header>
    <Body>
        <Action>
            <GetService>
                <Code>ABC</Code>
                <CodeValue>XYZ</CodeValue>
            </GetService>
        </Action>
    </Body> </Request>

However, this what I am getting back the following as the Sampler result:

Response code: Non HTTP response code: java.net.ConnectException Response message: Non HTTP response message: Connection refused

Response headers:

HTTPSampleResult fields: ContentType:
DataEncoding: null

I have made sure that I can ping my server. Its up and running.

Is there something else that I am missing here?

Thanks in advance!

2条回答
欢心
2楼-- · 2019-08-04 09:30
  1. You browser uses proxy to connect to the Internet and JMeter doesn't. Try hitting i.e. http://example.com domain with a single JMeter GET request and if it fails - configure JMeter to use the same proxy as browser does via the following command-line parameters:

    -H, --proxyHost <argument>
           Set a proxy server for JMeter to use
    -P, --proxyPort <argument>
           Set proxy server port for JMeter to use
    -N, --nonProxyHosts <argument>
           Set nonproxy host list (e.g. *.apache.org|localhost)
    -u, --username <argument>
           Set username for proxy server that JMeter is to use
    -a, --password <argument>
           Set password for proxy server that JMeter is to use 
    
  2. Double check your Server Name and Port values and validate them via i.e. telnet command. If telnet is able to connect - JMeter will be able as well as the error states that connection cannot be established.
  3. Make sure that you use correct HTTP method.
  4. You may also need to pass relevant Content-Type header value e.g. text/xml or application/soap+xml via HTTP Header Manager
查看更多
在下西门庆
3楼-- · 2019-08-04 09:47

I find it the easiest to just use a SOAP/XML-RPC Request for this kind of stuff. Simply enter the XML you want to send and the URL and make sure that Send SOAPAction is unchecked if you're not using it.

SOAP/XML-RPC Request

The problem you're having seems to be unrelated though. It looks like JMeter can't get a connection to the server. You should try it manually by using your browser and going to the URL you want to send the XML to. You should at least get a 400 error. "Connection Refused" looks more like the server isn't running.

查看更多
登录 后发表回答