Update file request results in 404 - c++

I'm trying to update an existing file. The documentation says to use a PUT request with the file id and resumable as upload type.
However I'm getting a 404 with this request:
PUT /upload/drive/v3/files/*****?uploadType=resumable HTTP/1.1
Authorization: *****
Connection: keep-alive
Content-Length: 0
Date: Thu, 12 Jul 2018 20:20:08 GMT
X-Upload-Content-Type: image/jpeg
Host: www.googleapis.com:443
See the response:
HTTP/1.1 404 Not Found
X-GUploader-UploadID: *****
Vary: Origin
Vary: X-Origin
Content-Type: text/html; charset=UTF-8
Content-Length: 9
Date: Thu, 12 Jul 2018 20:20:07 GMT
Server: UploadServer
Alt-Svc: quic=":443"; ma=2592000; v="44,43,39,35"
Changing to a PATCH request seems to solve the issue.

Could be wrong fileId as Remy suggests. Also could be a session expiry.
Or, could be a documentation error. The page you linked to says use PUT, but the reference page https://developers.google.com/drive/api/v3/reference/files/update says use PATCH

Related

Can't adjust buffer to fit data

I am trying to make an HTTP request the with EtherCard library, then get the full response. Using the code from the examples, I'm only able to capture the headers, which are then abruptly cut off. The issue seems to be that I can't make the buffer big enough to store the data, but the data, hence why it's cut off. But it's only 292 bytes.
Here is another question I asked trying to understand what the example code was doing: What is happening in this C/Arduino code?
Here is the data I'm trying to GET: http://jsonplaceholder.typicode.com/posts/1
String response;
byte Ethernet::buffer[800]; // if i raise this to 1000, response will be blank
static void response_handler (byte status, word off, word len) {
Serial.println("Response:");
Ethernet::buffer[off + 400] = 0; // if i raise 400 much higher, response will be blank
response = String((char*) Ethernet::buffer + off);
Serial.println(response);
}
See the comments above for what I've attempted.
Here is the output from the code above:
Response:
HTTP/1.1 404 Not Found
Date: Fri, 20 Jan 2017 12:15:19 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 2
Connection: close
Set-Cookie: __cfduid=d9714bd94284b999ceb0e87bc91705d501484914519; expires=Sat, 20-Jan-18 12:15:19 GMT; path=/; domain=.typicode.com; HttpOnly
X-Powered-By: Express
Vary: Origin, Accept-Encoding
Access-Control-Allow-Credentials: true
Cache-Control: no
As you can see, it's not the complete data, only some of the headers.
There are several problems here:
1) You get a HTTP 404 response, which means the resource was not found on the server. So you need to check your request.
2) You are cutting off the string at pos 400:
Ethernet::buffer[off + 400] = 0; // if i raise 400 much higher, response will be blank
That's why it stops after Cache-Control: no, which is exactly 400 bytes (byte 0-399).
You probably want Ethernet::buffer[off + len] = 0;, but you also need to check if that is not out of bounds (i.e. larger than your buffer size - that's probably why you get a 'blank' response).
For example, a 404 response from that server looks like this:
HTTP/1.1 404 Not Found
Date: Mon, 23 Jan 2017 07:00:00 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 2
Connection: keep-alive
x-powered-by: Express
Vary: Accept-Encoding
Access-Control-Allow-Credentials: true
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
x-content-type-options: nosniff
Etag: W/"2-mZFLkyvTelC5g8XnyQrpOw"
Via: 1.1 vegur
CF-Cache-Status: MISS
Server: cloudflare-nginx
CF-RAY: 32595301c275445d-xxx
{}
and the 200 response headers (from a browser):
HTTP/1.1 200 OK
Date: Mon, 23 Jan 2017 07:00:00 GMT
Content-Type: application/json; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
x-powered-by: Express
Vary: Accept-Encoding
Access-Control-Allow-Credentials: true
Cache-Control: public, max-age=14400
Pragma: no-cache
Expires: Mon, 23 Jan 2017 10:59:01 GMT
x-content-type-options: nosniff
Etag: W/"124-yv65LoT2uMHrpn06wNpAcQ"
Via: 1.1 vegur
CF-Cache-Status: HIT
Server: cloudflare-nginx
CF-RAY: 32595c4ff39b445d-xxx
Content-Encoding: gzip
So your buffer needs to be big enough to hold both the response headers and the data.
3) In the 200 response we see 2 things: the transfer is chunked, and gzipped (but the latter only happens when there is a Accept-Encoding: gzip header in the request.
The easiest way to handle this is to send a HTTP/1.0 request instead of HTTP/1.1 (chunked transfer and gzip are not allowed/available in HTTP/1.0).

Stop watching google push notifications

I am using the Google Reports API to watch for changes to resources, such as a user's Google Calendar activity events. To achieve this, a channel (or watchpoint) was created by following the steps here: https://developers.google.com/admin-sdk/reports/v1/reference/activities/watch
Now, I would like to stop watching a resource before the channel expires. I sent a POST request along with a access token in the header and the body contains the channel id and the resource id (https://developers.google.com/admin-sdk/reports/v1/reference/channels/stop). However I keep getting a 404 Not Found. Am I doing something wrong here?
All other requests using the same access token are working fine.
My request/response looks like this:
POST /admin/reports/v1/channels/stop HTTP/1.1
Host: www.googleapis.com
Content-length: 97
Content-type: application/json
Authorization: Bearer ya29.rAExOpnO_gatfyJvKWEVt8OsQ-LyaCyN3UUFjYzm0-3ExEBZ9an7WWfdDLqJspChQaiiIQ
{
"id": "5cfc250b-2faf-4f86-91b3-398326c6b4fb",
"resourceId": "A_HZ7mQy0Zpd6-TkQjr3aQlWd94"
}
HTTP/1.1 404 Not Found
Content-length: 9
X-xss-protection: 1; mode=block
X-content-type-options: nosniff
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Vary: Origin,X-Origin
Server: GSE
Pragma: no-cache
Cache-control: no-cache, no-store, max-age=0, must-revalidate
Date: Fri, 10 Jul 2015 17:10:40 GMT
X-frame-options: SAMEORIGIN
Content-type: text/html; charset=UTF-8
Not Found
Turns out the request URL specified in the documentation is wrong.
The correct one is
https://www.googleapis.com/admin/reports_v1/channels/stop
Issue reported here: https://code.google.com/a/google.com/p/apps-api-issues/issues/detail?id=3914

Sitecore Item Web API does not return any field

I am using the Sitecore Item Web API for a Sitecore 7.5 and 8. And in both I am getting a empty list for the fields in the JSON returned.
Sample of request:
GET http://sitecore8/-/item/v1/?sc_database=web&sc_itemversion=1&language=default&payload=Content&scope=s&sc_itemid=%7b11111111-1111-1111-1111-111111111111%7d HTTP/1.1
X-Scitemwebapi-Username: sitecore\admin
X-Scitemwebapi-Password: b
Host: sitecore8
Connection: Close
Response:
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.5
X-Powered-By: ASP.NET
Date: Mon, 18 May 2015 17:54:53 GMT
Connection: close
Content-Length: 597
{"statusCode":200,"result":{"totalCount":1,"resultCount":1,"items":[{"Database":"web","DisplayName":"sitecore","HasChildren":true,"Icon":"/temp/IconCache/Applications/32x32/Document.png","ID":"{11111111-1111-1111-1111-111111111111}","Language":"en","LongID":"/{11111111-1111-1111-1111-111111111111}","MediaUrl":"/temp/IconCache/Applications/48x48/Document.png","Name":"sitecore","Path":"/sitecore","Template":"System/Root","TemplateId":"{C6576836-910C-4A3D-BA03-C277DBD3B827}","TemplateName":"Root","Url":"~/link.aspx?_id=11111111111111111111111111111111\u0026amp;_z=z","Version":1,"Fields":{}}]}}
Does anybody has any idea what I am missing?
Tks a lot..
Damm.. the processor to get the fields were commented out in my configuration files.
<itemWebApiGetFields>
<!--<processor type="Sitecore.ItemWebApi.Pipelines.GetFields.GetFields, Sitecore.ItemWebApi" />-->
</itemWebApiGetFields>

Sitecore Item Web API - Template item not found error

I am trying to create a item via Item Web Api and I am not being able to figure out what is wrong with my call.
The template ID does exist as well as the parent ID.
POST:
POST /-/item/v1/?name=Foo&template=%23%7b57ABCEB7-25E5-4F73-88D8-9E66E79EA87C%7d%23&sc_database=master&payload=Content&fields=DataTest&sc_itemid=%23%7b110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9%7d%23 HTTP/1.1
X-Scitemwebapi-Username: sitecore\admin
X-Scitemwebapi-Password: b
Content-Type: application/x-www-form-urlencoded
Host: sandbox
Content-Length: 14
Expect: 100-continue
Proxy-Connection: Close
DataTest=Value
RESPONSE:
HTTP/1.1 200 OK
Cache-Control: no-cache, no-store
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/8.0
X-Powered-By: ASP.NET
Date: Wed, 19 Mar 2014 00:25:34 GMT
Content-Length: 65
{"statusCode":500,"error":{"message":"Template item not found."}}
Any ideas?
Thanks a lot!
There are some extra encoded characters in the request URL, your template and sc_itemid parameters are wrapped in %23 (#) characters.
POST
/-/item/v1/?name=Foo&template=%23%7b57ABCEB7-25E5-4F73-88D8-9E66E79EA87C%7d%23&sc_database=master&payload=Content&fields=DataTest&sc_itemid=%23%7b110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9%7d%23
HTTP/1.1
Check your code to make sure how they got there but removing them should fix the issue.

writing proper "HEAD" and "GET" request in winsock c++

Actually I was coding for downloading the files in HTTP using winsock c++ and to get the details I fired "HEAD" header..
(this is what actually I did)
HEAD /files/ODBC%20Programming%20in%20C%2B%2B.pdf HTTP/1.0
Host: devmentor-unittest.googlecode.com
Response was:
HTTP/1.0 404 Not Found
Content-Type: text/html; charset=UTF-8
Set-Cookie: PREF=ID=feeed8106df5e5f1:TM=1370157208:LM=1370157208:S=10bN4nrXqkcCDN5n; expires=Tue, 02-Jun-2015 07:13:28 GMT; path=/; domain=devmentor-unittest.googlecode.com
X-Content-Type-Options: nosniff
Date: Sun, 02 Jun 2013 07:13:28 GMT
Server: codesite_downloads
Content-Length: 974
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
But if I do:
GET /files/ODBC%20Programming%20in%20C%2B%2B.pdf HTTP/1.0
Host: devmentor-unittest.googlecode.com
The file sucessfully gets downloaded....
After then after I download, again if I fire the HEAD request... it also brings up the following
HTTP/1.0 200 OK
Content-Length: 320381
Content-Type: application/pdf
Content-Disposition: attachment; filename="ODBC Programming in C++.pdf"
Accept-Ranges: bytes
Date: Sun, 02 Jun 2013 05:47:11 GMT
Last-Modified: Sun, 11 Nov 2007 03:17:59 GMT
Expires: Sun, 09 Jun 2013 05:47:11 GMT
Cache-Control: public, max-age=604800
Server: DFE/largefile
//something like this.....
Question: why "HEAD" is returning the false "error not found" at first but the file gets downloaded in using "GET" and after downloading "HEAD" also returns goodies i need...where have i mistaken..
The file I am trying to download here is "http://devmentor-unittest.googlecode.com/files/ODBC%20Programming%20in%20C%2B%2B.pdf" (just for example)
The problem is not on your end. Google Code simply does not implement HEAD correctly. This was reported 5 years ago and is still an open issue:
Issue 660: support HTTP HEAD method for file download urls