Google storage (curl + PHP + create a dummy _$folder$) - php

Can anyone enlighten me how to create a _$folder$ using Google storage API? Here is the class that I have so far (I managed to list/filter files), but no success with creating a 'directory'. http://guy.codepad.org/lEO4J6hL
When I try to create a test_$folder$, this is what I send to the server:
PUT /test_$folder$ HTTP/1.1
Host: static.hotelpublisher.com.commondatastorage.googleapis.com
Date: Mon, 29 Nov 2010 19:45:49 GMT
Content-Length: 0
Content-Type: application/octet-stream
Content-MD5: 1B2M2Y8AsgTpgAmY7PhCfg==
Authorization: GOOG1 GOOGRVMFQJPKHRXAU3F6:gtzlxexMjBOafn5tOZKF7UZGv1I=
x-goog-acl: public-read
This is what I get in return:
<?xml version='1.0' encoding='UTF-8'?><Error><Code>MalformedHeaderValue</Code><Message>An HTTP header value was malformed.</Message><Date>mon, 29 nov 2010 19:34:23</Date></Error>
This is done following the Google provided documentation, thus I don't see why this does not work.

Hm... have you tried taking out the Content-MD5 header? It doesn't look like it's necessary since your Content-Length is 0.

Related

PHP read multiple event streams and act upon events

I'm currently struggeling with reading one (and eventually multiple) http event streams.
I have a camera that streams events to me and I'd like to consume those events to trigger some actions.
I'm using the following code for example to open the stream:
$stream = stream_get_contents(fopen('http://IP:port/live/events?param=123&param2=321', 'r'));
Now, when I just keep reading the stream with an echo, it times out eventually and then nothing hapens further more.
I need to be able to read the HTTP response. So I kinda have a continiously running GET request.
An example of the HTTP request is the following;
GET /live/events HTTP/1.1
Host: 192.168.1.101
Connection: keep-alive
Cookie: sid=60ab2b6b
Then a response would be;
HTTP/1.1 200 OK
Pragma: no-cache
Expires: Thu, 01 Dec 2003 16:00:00 GMT
Connection: close
Content-Type: multipart/mixed; boundary=IPCamEventStreamBoundary
Cache: no-cache
Accept-Ranges: none
--IPCamEventStreamBoundary
Content-Type: image/jpeg
Content-Length: 498749
X-Timestamp: 1620986982002
X-Image-Index: 1
X-Frame-Id: 521699
X-Frame-Timestamp: 757030579
X-Frame-Width: 2560
X-Frame-Height: 1920
binary data
--IPCamEventStreamBoundary
Content-Type: application/json
Content-Length: 308
X-Event-Index: 1
X-Timestamp: 1620986982042
{
"DetectorVersion" : 131072,
"DetectorID" : "{6309907F-5708-47D1-B410-50F02C8882FB}",
"DetectorClassID" : -835316578,
"EventTime" : "13265460582042",
"State" : "dsSignal",
"EventCode" : 100,
"EventInfo" : {},
"EventID" : "{4F34A399-9E02-1846-ADA7-98A2798B46B9}",
"DetectorEventType" : "detSignal"
}
What I need, is to be able to capture that JSON in the body and process it. This should be a continiously running script (using the Laravel framework commands). I have multiple of such stream sources and should be able to get them all at the same time, prefered not having to have a daemon for each camera.
Anyone who has an idea on how to handle this best?

Wrong type object for key serialNumbers in response dictionary. Expected NSArray but found __NSCFString

i have a web service set up for passbook the error log is logging this error:
Get serial #s task (for device 88a9cbef8e318f61, pass type pass.com.passbook, last updated (null); with web service url https://) encountered error: Server response was malformed (Wrong type object for key serialNumbers in response dictionary. Expected NSArray but found __NSCFString.)
the code in PHP when is not found :
$updatable_passes_payload['lastUpdated'] = '';
$updatable_passes_payload['serialNumbers'] = '';
sendResponse(204, json_encode($updatable_passes_payload), 'text/json');
when is found:
$update_time = date('Y-m-d H:i:s');
$updatable_passes_payload['lastUpdated'] = $update_time;
$updatable_passes_payload['serialNumbers'] = json_encode($types);
sendResponse(200, json_encode($updatable_passes_payload), 'text/json');
the web service json :
HTTP/1.1 200 OK
Connection: close
Transfer-Encoding: Identity
Content-Type: text/json
X-Powered-By: PHP/5.4.22
Server: Apache mod_fcgid/2.3.10-dev
Date: Sun, 01 Dec 2013 23:25:08 GMT
{"lastUpdated":"2013-12-01 23:25:09","serialNumbers":"[\"102058742\"]"}
i checked this json in a json validator online it returns OK
when is not found it returns
HTTP/1.1 204 No Content
Connection: close
Content-Type: text/json
X-Powered-By: PHP/5.4.22
Server: Apache mod_fcgid/2.3.10-dev
Date: Sun, 01 Dec 2013 23:35:17 GMT
for some reason is not returning any json when not found
any help will be appreciated
Your issue is with your JSON array. You have encapsulated your array in quotes so it is being interpreted as a string.
The following should work:
{"lastUpdated":"2013-12-01 23:25:09","serialNumbers":["102058742"]}

HTTP transfert encoding chunked 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.

Why REST PUT returns HTTP/1.x 405 Method Not Allowed

I tried this REST WS http://phprestsql.sourceforge.net/
When I select PUT verb and copy and paste in textbox
firstname=Jim
surname=Example
email=jim#example.org
company_uid=1
I do get this response error :
HTTP/1.x 405 Method Not Allowed
Date: Sun, 18 Aug 2013 16:50:06 GMT
Via: 1.1 varnish
Allow: GET, HEAD
Server: Apache/2.2.15 (CentOS)
Age: 0
Vary: Host, Accept-Encoding
Content-Type: text/html
Cache-Control: max-age=172800
X-Varnish: 244445725
Connection: keep-alive
Content-Length: 0
Expires: Tue, 20 Aug 2013 16:50:06 GMT
Why don't I get as expected
HTTP/1.x 201 Created
PUT requires you to know the specific resource ID already - it is intended to REPLACE the content of the current record with the content of a new record (that you provide). If you are just creating a new record that has never existed before and you don't want to replace or overwrite anything else, you should use POST.
From the website linked:
There are two ways to add a row to a table:
Using a PUT method we can write a resource to a specific URL, but to
do this we must already know the primary key we want to insert it at
(since the primary key forms part of the URL). The PUT method should
be used to create or overwrite a known named resource.
Using a POST method we can send a rows representation to a tables URL
and get it to append it to itself. The POST method should be used to
create a brand new resource as a sub-resource of a collection (and
when you want the server to make up the URL for you).

Exchange WebDAV 400 Bad Request: Why?

I have been using WebDAV in PHP directly using XML. I have managed to create emails with attachments and so forth, but when i try to create a contact, I keep getting "400 Bad Request". Here is the webdav query and how i'm executing it:
<?xml version="1.0"?>
<g:propertyupdate
xmlns:g="DAV:"
xmlns:c="urn:schemas:contacts:"
xmlns:e="http://schemas.microsoft.com/exchange/"
xmlns:mapi="http://schemas.microsoft.com/mapi/"
xmlns:x="xml:"
xmlns:cal="urn:schemas:calendar:"
xmlns:mail="urn:schemas:httpmail:">
<g:set>
<g:prop>
<g:contentclass>urn:content-classes:person</g:contentclass>
<e:outlookmessageclass>IPM.Contact</e:outlookmessageclass>
<c:givenName>JoLynn</c:givenName>
<c:middlename>Julie</c:middlename>
</g:prop>
</g:set>
</g:propertyupdate>
And response:
HTTP/1.1 400 Bad Request
Connection: close
Date: Mon, 05 Jul 2010 08:41:43 GMT
Server: Microsoft-IIS/6.0
MicrosoftOfficeWebServer: 5.0_Pub
X-Powered-By: ASP.NET
Content-Type: text/html
Content-Length: 1709
MS-WebStorage: 6.5.7638
And sending the data: $h->fetch($url, 0, null, $exchange_username, $exchange_password, "PROPPATCH")
Any help greatly appreciated!¬
I started with Troy Wolf's example code at http://www.troywolf.com/articles/php/exchange_webdav_examples.php
Ah i fixed it, forgot to send some headers with the request (content-type, depth and translate headers to be precise!)

Categories