Reputation: 93
I had a specific question in regards to curl. I want to call my xml page and I am executing something like this from my terminal:
curl -d @<xml page> <url>
However when i execute the following command, i get the following:
Invalid request structure
In my xml page request is as follows:
<example type="request">
<doLogin>
<userName>my_username</userName>
<password>my_password</password>
<...other details>
</doLogin>
</example>
How do i pass the parameters for username and password in the curl command?
Upvotes: 0
Views: 4592
Reputation: 185861
If you want to post a XML
file, try doing this :
curl -d "@./file.xml" -X POST -H 'Content-Type:text/xml' http://domain.tld/path
If instead the username/password is handled by basic auth, try doing this using an unix shell:
user=$(xmllint --xpath '/example/doLogin/userName/text()' file.xml)
pass=$(xmllint --xpath '/example/doLogin/password/text()' file.xml)
curl -u "$user:$pass" http://domain.tld/path
XML
file :
<?xml version="1.0" encoding="utf-8"?>
<example type="request">
<doLogin>
<userName>my_username</userName>
<password>my_password</password>
<...other details>
</doLogin>
</example>
Upvotes: 4
Reputation: 58254
Are you asking how you can send that XML file with a POST and yet have your custom user and password get used within that XML, all from a single command line?
If so, then piping the template XML file through sed to letting it fill in the correct values could be an idea, and then let curl read the file to post from its stdin.
$ sed -e "s/my_username/$user/g" -e "s/my_password/$password/g" < template_file | curl -d@- [URL]
Upvotes: 0