Getting response from one of the soap function php, after that sending this response as a parameter to another soap request, that time I need to extract the set-cookie from the previous response header here below my response header. I need to read set-cookie JSESSIONID element ?
HTTP/1.1 200 OK
Set-Cookie: **JSESSIONID=9A977E193F9B505B084D95C3028BAD0C.srv1816**;
Path=/webservices
Content-Type: text/xml;charset=UTF-8
Transfer-Encoding: chunked
Date: Mon, 15 Apr 2019 07:38:52 GMT
Set-Cookie: aeroID=12988141315553139361555313936504655;Path=/;
Expires=Sun, 09-Feb-2020 07:38:56 GMT
You could just read your JSESSIONID cookie like so :
First get your cookies :
import com.eviware.soapui.impl.wsdl.support.http.HttpClientSupport
def cookieStore= HttpClientSupport.getHttpClient().getCookieStore()
Then just find the one that interest you
def cookies = cookieStore.getCookies()
def jsessionidCookie
cookies.each {
if(it.name == "JSESSIONID")
jsessionidCookie= it
}
Related
I have an API and I've been trying to add cache control headers to it.
The API already makes use of PhpFastCache for server side caching but I wanted to add an additional layer of browser control caching. I came across this intelligent php cache control page and modified it slightly.
Using PhpFastCache, I do a check to see if the server side cache exists, if it doesn't then query the DB and output normally with a 200 response code. If the cache does exist then I do the following:
//get the last-modified-date of this very file
$lastModified=filemtime(__FILE__);
//get a unique hash of this file (etag)
$etagFile = md5( $CachedString->get() );
//get the HTTP_IF_MODIFIED_SINCE header if set
$ifModifiedSince=(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ? $_SERVER['HTTP_IF_MODIFIED_SINCE'] : false);
//get the HTTP_IF_NONE_MATCH header if set (etag: unique file hash)
$etagHeader=(isset($_SERVER['HTTP_IF_NONE_MATCH']) ? trim($_SERVER['HTTP_IF_NONE_MATCH']) : false);
//set last-modified header
header("Last-Modified: ".gmdate("D, d M Y H:i:s", $lastModified)." GMT");
//set etag-header
header("Etag: $etagFile");
//make sure caching is turned on
header('Cache-Control: public');
//check if page has changed. If not, send 304 and exit
if (#strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])==$lastModified || $etagHeader == $etagFile)
{
header("HTTP/1.1 304 Not Modified");
exit;
}else{
//Cache Match - Output Cache Result
header('Content-Type: application/json');
echo $CachedString->get();
}
I'm using this line to get the cached response as md5:
$etagFile = md5( $CachedString->get() );
Then doing a check to see if this md5 content has changed:
if (#strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE'])==$lastModified || $etagHeader == $etagFile)
{
header("HTTP/1.1 304 Not Modified");
exit;
}else{
//Cache Match - Output Cache Result
header('Content-Type: application/json');
echo $CachedString->get();
}
However I can never seem to get the 304 response header. It is ALWAYS a 200 code response header.
curl -I -L https://db.ygoprodeck.com/api/v7/cardinfo.php?name=Tornado%20Dragon
With the response always being:
HTTP/1.1 200 OK
Date: Tue, 17 Mar 2020 13:37:31 GMT
Content-Type: application/json
Connection: keep-alive
Set-Cookie: __cfduid=daaab295934a2a8ef966c2c70fe0955b91584452250; expires=Thu, 16-Apr-20 13:37:30 GMT; path=/; domain=.ygoprodeck.com; HttpOnly; SameSite=Lax
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET
Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With
Cache-Control: public
Last-Modified: Tue, 17 Mar 2020 13:15:53 GMT
Etag: 399b9ba2d69ab115f46faa44be04d0ca
Vary: User-Agent
CF-Cache-Status: DYNAMIC
Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
Server: cloudflare
CF-RAY: 57571be8a986a72f-DUB
Your request is being proxied through Cloudflare which has its own caching layer. If you test this direct to origin/with a grey clouded record are you getting a 304?
You said you were working on browser caching, browser is going to cache based on the max-age setting you send, but don't see one being set in the response.
I want a the value of the "token" from the json array from the response i get after performing a cUrl post request. after print_r($response); it prints out all that. but i just want the json string and one particular value with php.
Here is my response. I don't want all this before the response
HTTP/1.1 200 OK<br/>
Content-Type: application/json<br/>
Content-Length: 312<br/>
Connection: keep-alive<br/>
Vary: Accept-Encoding<br/>
Status: 200 OK<br/>
Cache-Control: max-age=0, private, must-revalidate<br/>
Date: Wed, 22 Mar 2017 12:52:25 GMT<br/>
Strict-Transport-Security: max-age=31536000<br/>
X-Request-Id: 9418df03bea4e4884522b703d0eec504<br/>
X-UA-Compatible: IE=Edge,chrome=1<br/>
ETag: "dd4de4d3a6e4e499d6a034ce784d2d76"<br/>
X-Runtime: 0.633173<br/>
X-Content-Type-Options: nosniff<br/>
X-Rack-Cache: invalidate, pass<br/>
X-Powered-By: Phusion Passenger 5.0.28<br/>
Server: nginx/1.10.0 + Phusion Passenger 5.0.28
{"response_code":"00","response_text":"Mobile wallet payment request has been issued.","description":"You will receive a bill prompt shortly on your number 0546653444 with invoice no. 201562656, kindly complete it.","transaction_id":"DTV408402","token":"8268dfffa46a16b0665a76","mobile_invoice_no":"201562656"}
You need to tell cURL that you don't want the header:
curl_setopt($ch, CURLOPT_HEADER, 0);
you can use php's explode() function on this response. Or you can adjust your curl request to not return headers with your requests.
$split=explode("\n\n",$response);
$array=json_decode($split[1],true);
var_dump($array);
if this does not work, modify explode function to split on "\r\n\r\n" instead of "\n\n";
you can do it with JSON decode.
$json = $Your_respone_variable;
$obj = json_decode($json);
print $obj->{'token'}; // token can be replaced by any other key of your JSON
For more informations take a look at:
http://php.net/manual/de/function.json-decode.php
I have this HTTP response content :
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Transfer-Encoding: chunked
Date: Mon, 12 Aug 2013 15:08:10 GMT
PK�Ctemps_attente.json���n� �߅9�Bw���VU��Uߠs���^��#�CGç��ͷ�r7G�3Hnp����^pYSu\#Qo%~x��FGa�Y�ا����S���-ua���t��j-���s�%э��+,g�xq.��������t�fb� �0:)�:�K�}^�N�L����>�щ%#�̲x`C#��m݃ :^��$~�i8���WzCh�a�ă���7t�O|��AX˂��UO$���<��y"�;�'F��]��{֘Ha}F��<��l6��o벰V���66t�&��f�Ť��x�H��툗���/PKA�Y�1�PK�CA�Y�1�temps_attente.jsonPK#q
I would like to know what format is the response and how to decompile to have the final response.
I tried to use this function: http_chunked_decode but I did not succeed.
The body (or at least what appears to be the body) of the response is not chunked.
It does appear to be compressed - with HTTP this should be expressly stated in the headers,
There is no blank line between the what appears to be the headers and what appears to be the body.
If this is really the response you are getting it's not HTTP - an off-the-shelf function is not going to make sense of it.
I am using PHP http_post_data() call to send data to a cakephp controller.I do it like this:
$response=http_post_data($url, $xml_data_encoded);
The data arrives ok to the destination and I get a response which holds the response status.In my case the status is number 1 which means -data delivered ok.As you can see from the code below I get not only the status number (which is at the bottom of the message) but also the whole http post header.How can I strip this message off the header code so that eventually the response message holds only the status number?
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Date: Thu, 10 Nov 2011 08:34:15 GMT
Server: Apache/2.2.17 (Ubuntu)
X-Powered-By: PHP/5.3.5-1ubuntu7.3
Set-Cookie: CAKEPHP=xxxxxxxxxxxxxxxx; expires=Fri, 18-Nov-2011 16:34:15 GMT; path=/XXXXXXXXXX/xxxxxxxx
P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
Vary: Accept-Encoding
Content-Length: 19
Content-Type: text/html
1
Btw, I also tried this:
HttpMessage::getBody(http_post_data($url, $xml_data_encoded));
and got no response at all.
Any help will be highly appreciated.
$response = http_post_data($url, $data);
preg_match_all('~HTTP/1\.[01]\s(\d{3})~', $response, $codes);
$codes would store all matches. Just print_r the array and look for desired keys.
Instead of a regular expression you can use http_parse_message
$response = http_parse_message(http_post_data($url, $data));
print $response->body;
When I send a 304 response. How will the browser interpret other headers which I send together with the 304?
E.g.
header("HTTP/1.1 304 Not Modified");
header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
Will this make sure the browser will not send another conditional GET request (nor any request) until $offset time has "run out"?
Also, what about other headers?
Should I send headers like this together with the 304:
header('Content-Type: text/html');
Do I have to send:
header("Last-Modified:" . $modified);
header('Etag: ' . $etag);
To make sure the browser sends a conditional GET request the next time the $offset has "run out" or does it simply save the old Last Modified and Etag values?
Are there other things I should be aware about when sending a 304 response header?
This blog post helped me a lot in order to tame the "conditional get" beast.
An interesting excerpt (which partially contradicts Ben's answer) states that:
If a normal response would have included an ETag header, that header must also be included in the 304 response.
Cache headers (Expires, Cache-Control, and/or Vary), if their values might differ from those sent in a previous response.
This is in complete accordance with the RFC 2616 sec 10.3.5.
Below a 200 request...
HTTP/1.1 200 OK
Server: nginx/0.8.52
Date: Thu, 18 Nov 2010 16:04:38 GMT
Content-Type: image/png
Last-Modified: Thu, 15 Oct 2009 02:04:11 GMT
Expires: Thu, 31 Dec 2010 02:04:11 GMT
Cache-Control: max-age=315360000
Accept-Ranges: bytes
Content-Length: 6394
Via: 1.1 proxyIR.my.corporate.proxy.name:8080 (IronPort-WSA/6.3.3-015)
Connection: keep-alive
Proxy-Connection: keep-alive
X-Junk: xxxxxxxxxxxxxxxx
...And its optimal valid 304 counterpart.
HTTP/1.1 304 Not Modified
Server: nginx/0.8.52
Date: Thu, 18 Nov 2010 16:10:35 GMT
Expires: Thu, 31 Dec 2011 16:10:35 GMT
Cache-Control: max-age=315360000
Via: 1.1 proxyIR.my.corporate.proxy.name:8080 (IronPort-WSA/6.3.3-015)
Connection: keep-alive
Proxy-Connection: keep-alive
X-Junk: xxxxxxxxxxx
Notice that the Expires header is at most Current Date + One Year as per RFC-2616 14.21.
The Content-Type header only applies to responses which contain a body. A 304 response does not contain a body, so that header does not apply. Similarly, you don't want to send Last-Modified or ETag because a 304 response means that the document hasn't changed (and so neither have the values of those two headers).
For an example, see this blog post by Anne van Kesteren examining WordPress' http_modified function. Note that it returns either Last-Modified and ETag or a 304 response.