Exchange WebDAV 400 Bad Request: Why? - php

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!)

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.

Extracting the response body from http_post_data in PHP

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;

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

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.

Categories