Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BAD REQUEST #1473

Closed
shaka25 opened this issue May 8, 2017 · 5 comments
Closed

BAD REQUEST #1473

shaka25 opened this issue May 8, 2017 · 5 comments
Labels

Comments

@shaka25
Copy link

shaka25 commented May 8, 2017

SOAP CALL

I did this

ENDPOINT : http://www.odfl.com/TraceWebServiceWeb/services/Trace

REQUEST : <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:trac="http://trace.odfl.com"><soapenv:Header/><soapenv:Body><trac:getTraceData><trac:pro>6916221036</trac:pro><trac:type>P</trac:type></trac:getTraceData></soapenv:Body></soapenv:Envelope>


USERNAME AND PASSWORD are place in the property see code example below


int postrequest(int is_https)
{
    //writing to file initially
	struct curl_slist *header = NULL;
    CURL *curl;
    CURLcode res;

	//For header below function is getting used with different header content https://curl.haxx.se/libcurl/c/curl_slist_append.html
	header = curl_slist_append (header, "Content-Type:HTTP/XML");
	//header = curl_slist_append (header, "Content-Type: text/xml;charset=UTF-8");
	
   // header = curl_slist_append (header, "SOAPAction: myur1");
	 header = curl_slist_append (header, "SOAPAction: """);
    header = curl_slist_append (header, "Transfer-Encoding: chunked");
    //header = curl_slist_append (header, "Expect:");

	//https://curl.haxx.se/libcurl/c/curl_easy_init.html
    curl = curl_easy_init();

	if(is_https == 1)//if https url is getting used
	{
		curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, TRUE); //https://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYPEER.html
		curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2); //https://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYHOST.html
		curl_easy_setopt (curl, CURLOPT_CAINFO, ".\\cacert.pem"); //https://curl.haxx.se/libcurl/c/CURLOPT_CAINFO.html
	}

    if(curl) 
	{
		//https://curl.haxx.se/libcurl/c/CURLOPT_TCP_KEEPALIVE.html
		/* enable TCP keep-alive for this transfer */
		curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1L);
		/* keep-alive idle time to 120 seconds */
		curl_easy_setopt(curl, CURLOPT_TCP_KEEPIDLE, 120L);
		/* interval time between keep-alive probes: 60 seconds */
		curl_easy_setopt(curl, CURLOPT_TCP_KEEPINTVL, 60L);
		/* ask libcurl to show us the verbose output */
		//curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
        curl_easy_setopt(curl, CURLOPT_URL, endpoint); //https://curl.haxx.se/libcurl/c/CURLOPT_URL.html
		if (flag == TRUE)
		{
			 curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "gzip");
			// curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "http://www.odfl.com/TraceWebServiceWeb/services/Trace");
			 curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
			 curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0");
			 curl_easy_setopt(curl, CURLOPT_USERNAME, username);
			 curl_easy_setopt(curl, CURLOPT_PASSWORD, password);
			 //curl_easy_setopt(curl, CURLOPT_USERPWD, credential); //"myname:thesecret"  //
		}
        curl_easy_setopt(curl, CURLOPT_POST, 1L); //https://curl.haxx.se/libcurl/c/CURLOPT_POST.html
        curl_easy_setopt(curl, CURLOPT_READFUNCTION, NULL);  //Reads xml request from file (https://curl.haxx.se/libcurl/c/CURLOPT_READFUNCTION.html)
        curl_easy_setopt(curl, CURLOPT_READDATA, (void *)inpfile); //https://curl.haxx.se/libcurl/c/CURLOPT_READDATA.html
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);  //Writes data to file (https://curl.haxx.se/libcurl/c/CURLOPT_WRITEFUNCTION.html)
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)outfile);  //(https://curl.haxx.se/libcurl/c/CURLOPT_WRITEDATA.html)
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, header); //https://curl.haxx.se/libcurl/c/CURLOPT_HTTPHEADER.html
        curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)-1); //https://curl.haxx.se/libcurl/c/CURLOPT_POSTFIELDSIZE_LARGE.html
        curl_easy_setopt(curl, CURLOPT_VERBOSE,1L);  //https://curl.haxx.se/libcurl/c/CURLOPT_VERBOSE.html  
		curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errors);//https://curl.haxx.se/libcurl/c/CURLOPT_ERRORBUFFER.html
        res = curl_easy_perform(curl);//First set all the parameters using above function then perform action (https://curl.haxx.se/libcurl/c/curl_easy_perform.html)
		
		if (res != CURLE_OK)
		{
			 strcat(response,  "\n");
			 strcat(response,  "\n");
			 strcat(response,  "-----Curl Readable Error Text...-----\n");
			 strcat(response,  errors);
			 strcat(response,  curl_easy_strerror(res)); 
			 strcat(response,  "-------------------------------------\n");
			 fprintf(logfile, response);
			 fflush(logfile);
		}
		curl_slist_free_all(header);
		curl_easy_cleanup(curl); //Cleaning up all the set data (https://curl.haxx.se/libcurl/c/curl_easy_cleanup.html)

        return 1;
    }

	return 0;
}

I expected the following

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Header>
      <WorkContext xmlns="http://oracle.com/weblogic/soap/workarea/">rO0ABXetACF3ZWJsb2dpYy5hcHAudHJhY2Utd2Vic2VydmljZS1hcHAAAADWAAAAI3dlYmxvZ2ljLndvcmthcmVhLlN0cmluZ1dvcmtDb250ZXh0AAUxLjAuOAAhd2VibG9naWMuYXBwLmZ1bGwtcHJvLWhpc3RvcnktYXBwAAAA1gAAACN3ZWJsb2dpYy53b3JrYXJlYS5TdHJpbmdXb3JrQ29udGV4dAAGMS4wLjExAAA=</WorkContext>
   </S:Header>
   <S:Body>
      <p231:getTraceDataResponse xmlns:p231="http://trace.odfl.com">
         <p231:getTraceDataReturn>
            <p231:proNum>06916221036</p231:proNum>
            <p231:proDate>05/09/2017 Estimated</p231:proDate>
            <p231:statusCode>TPD</p231:statusCode>
            <p231:status>Awaiting Delivery</p231:status>
            <p231:appointment>Set for 05/09/2017 11:00AM</p231:appointment>
            <p231:pieces>4</p231:pieces>
            <p231:weight>2915</p231:weight>
            <p231:po>507346</p231:po>
            <p231:bol>B004678</p231:bol>
            <p231:trailer/>
            <p231:signature/>
            <p231:origTerminal>SPL</p231:origTerminal>
            <p231:origAddress>180 TALMADGE ROAD</p231:origAddress>
            <p231:origState>NJ</p231:origState>
            <p231:origName>SOUTH PLAINFIELD, NJ</p231:origName>
            <p231:origCity>EDISON</p231:origCity>
            <p231:origZip>08817</p231:origZip>
            <p231:origPhone>(800) 554-6335</p231:origPhone>
            <p231:origFax>(732) 248-9618</p231:origFax>
            <p231:destTerminal>LAS</p231:destTerminal>
            <p231:destAddress>1225 W. WASHINGTON BLVD.</p231:destAddress>
            <p231:destState>CA</p231:destState>
            <p231:destName>LOS ANGELES, CA</p231:destName>
            <p231:destCity>MONTEBELLO</p231:destCity>
            <p231:destZip>90640</p231:destZip>
            <p231:destPhone>(800) 245-6533</p231:destPhone>
            <p231:destFax>(323) 887-8091</p231:destFax>
            <p231:delivered>N</p231:delivered>
            <p231:url/>
            <p231:type>P</p231:type>
            <p231:scac/>
            <p231:errorMessage/>
            <p231:guaranteed>N</p231:guaranteed>
            <p231:call>N</p231:call>
         </p231:getTraceDataReturn>
      </p231:getTraceDataResponse>
   </S:Body>
</S:Envelope>

curl/libcurl version

CURL 7.54.0

[curl -V output]

<HTML><HEAD>
<TITLE>Bad Request</TITLE>
</HEAD><BODY>
<H1>Bad Request</H1>
Your browser sent a request that this server could not understand.<P>
Reference&#32;&#35;7&#46;e1d96bd1&#46;1494270546&#46;14c30ab4
</BODY>
</HTML>

operating system

MS SERVER 2012 R2

@bagder
Copy link
Member

bagder commented May 8, 2017

Your code snippet as shown is incomplete so we can't easily run it and see for ourselves. You also didn't mention what your code actually sent or how it differed to what you expected. Can you elaborate?

Also, how did your application do in regards to request headers compared to what you wanted it to send?

(Tip: https://httpbin.org/ is a neat service to work out test shots against to make sure applications do exactly what we want them to...)

@bagder bagder added the HTTP label May 8, 2017
@jay
Copy link
Member

jay commented May 9, 2017

This is an issue tracker, in the future please post your libcurl questions to curl-library. There are at least two problems with your code:

First problem: Server returns error HTTP/1.1 411 Length Required. That is because you're using header = curl_slist_append (header, "Transfer-Encoding: chunked"); and the server does not accept chunked encoding for those requests. There are two ways to deal with that, 1) read the xml file into memory and pass it to CURLOPT_POSTFIELDS; or 2) get the file size and pass it to CURLOPT_POSTFIELDSIZE_LARGE. Here is an example of the latter using fstat:

#include <sys/stat.h>
...
FILE *inpfile = fopen("input file","rb"); /* open the file in binary mode */
...
struct stat stbuf = { 0, };
if(fstat(fileno(inpfile), &stbuf) || stbuf.st_size < 0) {
  /* file size unknown, bail out */
}
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, (curl_off_t)stbuf.st_size );

Note in Windows the file size in st_size is 32-bits by default and the value will be incorrect if the file size is larger. While I doubt that's a problem with your xml file, if you're sending other larger files in Windows use struct _stati64 and _fstati64() instead.

Second problem: Server returns error HTTP/1.1 415 Unsupported Media Type. That is because of header = curl_slist_append (header, "Content-Type:HTTP/XML");. I'm pretty sure HTTP/XML is not valid I've never heard of that. Remove that and use the one you had commented out header = curl_slist_append (header, "Content-Type: text/xml;charset=UTF-8");.

Also one thing that may be a problem is stating you accept gzip via curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, "gzip");. If your libcurl doesn't support gzip and the server returns Content-Encoding: gzip then libcurl doesn't have the ability to decode it, so unless you're doing it on your own I wouldn't do that. I would instead set it to an empty string curl_easy_setopt(curl, CURLOPT_ACCEPT_ENCODING, ""); which will send gzip in Accept-Encoding only if your libcurl supports automatically decoding it in the response.

@jay jay closed this as completed May 9, 2017
@shaka25
Copy link
Author

shaka25 commented May 9, 2017

well, I email my issue to the email you recommend and crickets nothing at all.

@shaka25
Copy link
Author

shaka25 commented May 9, 2017

@jay
Copy link
Member

jay commented May 9, 2017

well, I email my issue to the email you recommend and crickets nothing at all.
curl-users-request@cool.haxx.se

That's the subscription confirmation address for curl-users I believe, I'd guess that address is automated to subscribe and unsubscribe. To e-mail curl-users after subscribing to that list you would e-mail curl-users@cool.haxx.se. But in your case this is a libcurl issue so as I mentioned if you need to ask libcurl questions subscribe to curl-library. Then to ask a question you would e-mail the list at curl-library@cool.haxx.se.

@lock lock bot locked as resolved and limited conversation to collaborators May 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants