How to properly create a bin using mockbin API? - php

I'm trying to create a bin using mockbin API. I tried PHP/cUrl, SoapUI and Postman, but I keep getting empty response body:
Request:
POST /bin/create/view HTTP/1.1
Host: mockbin.org
Content-Type: application/json
Accept: application/json
Cache-Control: no-cache
Response:
HTTP/1.1 200 OK
Date: Tue, 12 Jan 2016 13:21:50 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: __cfduid=d183c7edefea549cc0bbe219ac11fe7c81452604909; expires=Wed, 11-Jan-17 13:21:49 GMT; path=/; domain=.mockbin.org; HttpOnly
Vary: X-HTTP-Method-Override, Accept, Accept-Encoding
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST
Access-Control-Allow-Headers: host,connection,accept-encoding,x-forwarded-for,cf-ray,x-forwarded-proto,cf-visitor,content-type,accept,user-agent,via,cf-connecting-ip,x-request-id,x-forwarded-port,connect-time,x-request-start,total-route-time,content-length
Access-Control-Allow-Credentials: true
Content-Encoding: gzip
Via: 1.1 vegur
Server: cloudflare-nginx
CF-RAY: 26392aae22092ac1-WAW
Expected response:
HTTP/1.1 200 OK
Location: http://mockbin.org/3c149e20-bc9c-4c68-8614-048e6023a108
Content-Type: application/json; charset=utf-8
Content-Length: 38
"3c149e20-bc9c-4c68-8614-048e6023a108"
Other API methods work correctly, i.e. echo.

It looks like there is an error in the mockbin API docs. I have installed it locally and checked sent request when creating mockbin using html form. It seems the proper request is:
POST /bin/create HTTP/1.1
Host: mockbin.com
Accept: application/json
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
response=%7B%22status%22%3A200%2C%22statusText%22%3A%22OK%22%2C%22httpVersion%22%3A%22HTTP%2F1.1%22%2C%22headers%22%3A%5B%5D%2C%22cookies%22%3A%5B%5D%2C%22content%22%3A%7B%22mimeType%22%3A%22text%2Fplain%22%2C%22text%22%3A%22%22%7D%7D

Related

In PHP, While adding events in icalendar through CALDAV protocol, Received unknown HTTP status

I am working on project based on inserting events in icalendar(iPhone) through CALDAV protocol using PHP language
In localhost the code is working fine.. when adding the same code to server using some functions, received unknown HTTP status..
I tried using dataType:"text/plain" and also I tried contentType, still not fixed.. I removed ajax function.. directly link to file.. still its showing ame error.. sometimes its shows HTTP/1.1 500 Internal Server Error and http/1.1 415 unsupported media type
last request:
PUT /rpc/calendars/mediaj11/calendar~722ea7444446*******/.ics HTTP/1.1
Host: mail.mediajenie.com:2080
Authorization: Basic **********
User-Agent: cURL based CalDAV client
Accept: */*
Content-type: text/calendar; encoding="utf-8"
Depth: 1
Content-Length: 556
last response:
HTTP/1.1 500 Internal Server Error
Date: Fri, 28 Jun 2019 10:10:48 GMT
Server: cPanel
Persistent-Auth: false
Host: mail.mediajenie.com:2080
Cache-Control: no-cache, no-store, must-revalidate, private
Connection: Keep-Alive
Pragma: no-cache
Vary: Accept-Encoding
Content-Length: 3011
Content-Type: text/html; charset=UTF-8
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Set-Cookie: PHPSESSID=5e8045144d7823ac82049d0c7ad40247; path=/
Set-Cookie: horde_secret_key=5e8045144d7823ac82049d0c7ad40247; path=/; domain=mail.mediajenie.com; HttpOnly
Set-Cookie: default_horde_view=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; Max-Age=0; path=/; domain=mail.mediajenie.com
X-Powered-By: PHP/7.2.7

How to log the cURL calls into a file without using Wireshark to capture packets?

I am using PHP and cURL to send in HTTP request to a REST API. However, I need to validate some data going in/out.
How can I get a copy of the entire request logged into a file?
I have added this line to my request
curl_setopt($ch, CURLOPT_VERBOSE, true);
I am hoping I can get a copy to look like this saves to a log file.
--- START REQUEST
POST /icws/3048186002/interactions/3002853105 HTTP/1.1
Host: servername:8018
Accept: */*
Cookie: icws_3048186002=64425290-29e5-432a-9ee1-c303cdee1f79
ININ-ICWS-CSRF-Token: WAp3cmF0Y2xpZmZlWBJJQ1dTLUFQSS1jb25uZWN0b3JYJGQwYjhlMWRhLTZlOTktNGIwMC05NGNlLTY5MDdkZjUwOWI5Y1gJMTAuMC40LjE4
ININ-ICWS-Session-ID: 3048186002
Content-Type: application/json
Content-Length: 35
{"attributes":{"logged":1}}
--- END REQUEST
--- START RESPOND
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Content-Type: application/vnd.inin.icws+JSON; charset=utf-8
Date: Wed, 02 Sep 2015 20:39:26 GMT
Server: HttpPluginHost
Content-Length: 0
--- END RESPOND
How can I capture this data without having to use WireShark? I would think cURL and PHP are advanced enough to allow you to log such a thing.

CORS not working in Firefox

I am trying to load data into a jQuery dialog via ajax but the request is failing in Firefox (34.0.5). Works fine and I get no complaints in Chrome and Safari.
My apache conf contains:
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods: "PUT, GET, POST, DELETE, OPTIONS"
Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept"
The jQuery is simply:
$('#dialog').load('example.php', function() { $('#dialog').dialog('open'); });
Firefox responds with the following console error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.example.com/example.php. This can be fixed by moving the resource to the same domain or enabling CORS.
Inspecting the response headers from the ajax request they all seem to be intact and inline with what's declared in apache. Should I be including some other directive or changing the configuration in some way for this to work?
UPDATE: At the root of the issue is the fact that I'd like both example.com and www.example.com to function the same. The site in question always has a tag in the header <base href="www.example.com" /> in both instances as this is part of the default site framework. I've since discovered that removing this link allows the ajax request to work on example.com, even when it still specifically calls a resource from the www subdomain.
Interestingly, many aspects of the request and response headers change when this tag is removed. For anyone who might have a clue about the implications here I'm pasting both the request and response headers below.
Here are the headers with <base> tag removed. In this case the ajax call was successful:
RESPONSE
HTTP/1.1 200 OK
Date: Sun, 18 Jan 2015 22:11:04 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.5
Set-Cookie: PHPSESSID=xxx; path=/; HttpOnly
language=en; expires=Tue, 17-Feb-2015 22:11:04 GMT; Max-Age=2592000; path=/; domain=www.example.com
currency=CAD; expires=Tue, 17-Feb-2015 22:11:04 GMT; Max-Age=2592000; path=/; domain=www.example.com
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, public
Pragma: no-cache
Content-Encoding: gzip
access-control-allow-methods: PUT, GET, POST, DELETE, OPTIONS
access-control-allow-origin: *
access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept
Content-Length: 1515
Connection: close
Content-Type: text/html; charset=utf-8
REQUEST
GET /example.php HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:34.0) Gecko/20100101 Firefox/34.0 FirePHP/0.7.4
Accept: text/html, */*; q=0.01
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://example.com/
Origin: http://example.com
x-insight: activate
Connection: keep-alive
Cache-Control: max-age=0
And here are the headers with the <base> tag intact. These headers reflect the scenario where the ajax call failed. It's worth noting that the 'Location' field in the response header says 'https' even though this was not happening over an https connection:
RESPONSE
HTTP/1.1 302 Found
Date: Sun, 18 Jan 2015 22:12:26 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.5
Set-Cookie: PHPSESSID=xxx; path=/; HttpOnly
language=en; expires=Tue, 17-Feb-2015 22:12:26 GMT; Max-Age=2592000; path=/; domain=www.example.com
currency=CAD; expires=Tue, 17-Feb-2015 22:12:26 GMT; Max-Age=2592000; path=/; domain=www.example.com
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, public
Pragma: no-cache
Status: 302
Location: https://www.example.com/index.php
access-control-allow-methods: PUT, GET, POST, DELETE, OPTIONS
access-control-allow-origin: *
access-control-allow-headers: Origin, X-Requested-With, Content-Type, Accept
Content-Length: 0
Connection: close
Content-Type: text/html
REQUEST
OPTIONS /example.php HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:34.0) Gecko/20100101 Firefox/34.0 FirePHP/0.7.4
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Origin: http://example.com
Access-Control-Request-Method: GET
Access-Control-Request-Headers: x-requested-with
x-insight: activate
Connection: keep-alive
Cache-Control: max-age=0
According to MDN, you can't use the wildcard for "credentialed requests", so maybe your request falls in that category.

How can i log response code from server

i need to log the response header/code from the server?
How can i do this? With NginX or with PHP/Curl?
An example:
(This i the request from the client)
----------------Request-------------------------
GET /download.php?request=abc123xyz&link=http%3A%2F%2Fyoutube.com%2Fwatch?v=pRPOztxXWlQ HTTP/1.1
Host: api.example.com
Accept-Encoding: gzip,deflate
Cache-Control: no-cache
Pragma: no-cache
Accept-Language: de, en-gb;q=0.9, en;q=0.8
Accept: application/json
User-Agent: JDownloader
Answer from my Server (Response Code/Header)
----------------Response Information------------
Connection-Time: keep-Alive
----------------Response------------------------
HTTP/1.1 200 OK
Server: nginx
Date: Fri, 28 Nov 2014 12:03:32 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: keep-alive
Strict-Transport-Security: max-age=63072000; includeSubDomains
X-Frame-Options: DENY
X-Content-Type-Options: nosniff
------------------------------------------------
I need this, because i have sometimes problems with the download of different files. My service downloads videos from some streamhoster like youtube. The output of the response code helps me to know if this a problem with my server or with the external downloader (JDownloader, Load!, ...)
Add header content in your access log with $http_<my_header> variables where <my_header> is the desired header name in lower can with dashes replaced by underscores. For instance X-Frame-Options could be logged with $http_x_frame_options added to access logformat.

Header Type change to application/json not changing

header type of the
response from "text/html" to "application/json". Other then this
am using as header type as
header("Content-Type", "application/json;charset=UTF-8")
But not change.
Status Code: 200 OK
Connection: keep-alive
Content-Type: text/html
Date: Wed, 19 Nov 2014 05:49:55 GMT
Server: Apache mod_fcgid/2.3.10-dev
Vary: User-Agent
Via: 1.1 (external)pdc.amw.lan (squid/3.3.8), 1.1 (frontal)pdc.amw.lan (squid/3.3.8)
X-Cache: MISS from (external)pdc.amw.lan, MISS from (frontal)pdc.amw.lan
X-Cache-Lookup: MISS from (external)pdc.amw.lan:3130, MISS from (frontal)pdc.amw.lan:0
X-Powered-By: PHP/5.4.34
Set header as follows, not like header("Content-Type", "application/json;charset=UTF-8")
header("Content-Type: application/json");

Categories