Google translate API: cannot send more than 2000 characters per request - google-translate

The Google translate API FAQ at https://developers.google.com/translate/v2/faq#technical states that the maximum number of characters per request is 5000. However, I am unable to send more than 2000 characters without getting HTTP error 414: The requested URL /translate... is too large to process.
I am getting this from my .NET app but have also reproduced the same error from Fiddler.
Below is the URL I am sending (just over 2000 characters). Am I misunderstanding the 5000 character limit?
https://www.googleapis.com/language/translate/v2?key=MYKEY-MYKEY-MYKEY-MYKEY-MYKEY-MYKEY-KEY&source=en&target=es&q=From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0AIf%20traveling%20to%20the%20west%20From%20Sparta%3A%0D%0A

You'll need to POST the data if you wish to process more than 2000 characters:
All other query parameters are optional. The URL for the GET,
including parameters, must be less than 2K characters.
Note: You can also use POST to invoke the API if you want to send more
data in a single request
https://developers.google.com/translate/v2/using_rest

Related

HTTP health check - GET or HEAD and 200 or 204 response?

I’m wondering if there is a general convention for this: When implementing a HTTP health check for any given application where you are not interested in any response body but just the status code, what would the default/expected endpoint look like?
Using a HEAD request - and returning 200 or 204 status code (which one of those?)
Using a GET with 204
something else?
As of my experience, people use mostly GET and 200. A health check wouldn't respond too much content, so no use of making a HEAD request. But this is mostly the case with a dedicated health check URL.
Today's cloud systems often use Kubernetes or OpenShift. They appear to use a GET request. I think they'll probably want to get a 200ish response code, so 200-299:
https://docs.openshift.com/enterprise/3.0/dev_guide/application_health.html
https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
Another example, Drupal defines the HTTP response code to be 200:
https://www.drupal.org/project/health_check_url
In Oracle's Infrastructure-as-a-Service docs you can choose between GET and HEAD requests, but the default is HEAD:
https://docs.oracle.com/en-us/iaas/api/#/en/healthchecks/20180501/HttpMonitor/
Use a GET with 204 possibly supporting also HEAD with same status code
A HEAD should give the same response as GET but without response body, so you should first know/define what the GET response gives out in terms of headers (and status code), then, if you want, you can support also HEAD on the same endpoint, returning the same status, in this case 204.
Note that if GET employee/34 anwswers with 404 also HEAD must anwser with same code. That means one must do the same work as for GET: check if employee esists, set status etc. but must not write any response. Tomcat supports this automatically as it uses for HEAD request a response object that never writes to the "real" response, so one can use same code handling GET
For a check one may consider also TRACE but it produces a response body / output mirroring what you send to it, is different, I haven't seen implemented anywhere.
TRACE allows the client to see what is being received at the other
end of the request chain and use that data for testing or diagnostic
information.

HTTP request caputure (hidden)

I am trying to analyse http posts and get requests made to google finance.
I use Fiddler to view requests, but I don't understand how the real time quotes data has been transferred, as there are no calls made to the server.

Coinbase HTTP Request for Ether Spot Price

I can currently issue the following request: https://api.coinbase.com/v2/prices/spot?currency=USD and receive a json response with the current (spot) price of BitCoin (BTC).
What I want is to retrieve that information for Ether (ETH). I note that the HTTP request that I am using does not specify BTC, it just defaults to that.
I have reviewed the Coinbase API without success in locating an answer.
I was just wondering if anyone is aware of an HTTP request to obtain that data, or if this request is not currently supported via HTTP.
tia
The Coinbase API docs, https://developers.coinbase.com/api/v2#get-spot-price shows the following URI structure for getting the spot price for Bitcoin (BTC) or Ethereum (ETH), which is different from what you have posted.
https://api.coinbase.com/v2/prices/:currency_pair/spot
The part of the url indicated as :currency_pair is a string containing
the symbol for the coin, a hyphen and then 'USD', such as BTC-USD or ETH-USD.
I am able to get BTC and ETH spot prices from the api with the following:
https://api.coinbase.com/v2/prices/BTC-USD/spot
https://api.coinbase.com/v2/prices/ETH-USD/spot

SoundCloud API: GET succeeds, HEAD fails

I use the SoundCloud API to retrieve the stream URL for a streamable track.
I follow the redirect and I end up with an URL that looks like:
http://ec-media.soundcloud.com/eodihgiuh.128.mp3?<a string>
AWSAccessKeyId=<access key>
&Expires=<timestamp>
&Signature=<signature>
or
http://ak-media.soundcloud.com/euieuieie.128.mp3?
AWSAccessKeyId=<access key>
&Expires=<timestamp>
&Signature=<signature>
&__gda__=<a string>
Then I start streaming the MP3 data at this URL.
First I send a HEAD request to read the Content-Length header, so that I know how many GET requests I will have to send in order to play the whole song.
Then I send several partial GET requests, each one with a different Range header.
The problem is that sometimes the HEAD request returns a 403 status code, even though a GET request to the exact same URL returns with a 200 status code. It seems that this happens if and only if the host is ak-media.soundcloud.com.
Is this supposed to happen? I expected the HEAD request to return exactly the same headers as the GET request, only without the body response.
Cheers,
PB
P.S: I should probably mention that my code is not running on a computer, but on an audio device with a tiny 8-bit processor which has extremely limited resources.
Unfortunately, currently we only offer guaranteed proper response for GET requests.
As a hack, you could try to do requests with very short ranges.

Does sending POST data to a server that doesn't accept post data recieve the data?

I am setting up a back end API in a script of mine that contacts one of my sites by sending XML to my web server in the form of POST data. This script will be used by many and I want to limit the bandwidth waste for people that accidentally turn the feature on without a proper access key.
I will be denying requests that do not have the correct access key by maybe generating a 403 access code.
Lets say the POST data is ~500kb of data. Does the server receive all 500kb of data when this attempt is made regardless of the status code?
How about if I made the url contain the key mydomain/api/123456789 and generate 403 status on all bad access keys.
Does the POST data still get sent/received regardless or is it negotiated before the data is finally sent.
Thanks in advance!
Generally speaking, the entire request will be sent, including post data. There is often no way for the application layer to return a response like a 403 until it has received the entire request.
In reality, it will depend on the language/framework used and how closely it is linked to the HTTP server. Section 8.2.2 of RFC2616 HTTP/1.1 specification has this to say
An HTTP/1.1 (or later) client sending
a message-body SHOULD monitor the
network connection for an error status
while it is transmitting the request.
If the client sees an error status, it
SHOULD immediately cease transmitting
the body. If the body is being sent
using a "chunked" encoding (section
3.6), a zero length chunk and empty trailer MAY be used to prematurely
mark the end of the message. If the
body was preceded by a Content-Length
header, the client MUST close the
connection.
So, if you can find a language environemnt closely linked with the HTTP server (for example, mod_perl), you could do this in a way which does comply with standards.
An alternative approach you could take is to make an initial, smaller request to obtain a URL to use for the larger POST. The application can then deny providing the URL to clients without an appropriate key.
Here is great book about RESTful Web Services, where it's explained how HTTP works: http://oreilly.com/catalog/9780596529260
You can consider any request as envelope, where on top of it it's written address (URL), some properties (HTTP Headers) and inside it there's some data (if request is initiated by post method). So as you might guess you can't receive envelope partially.
Oh I forgot, it's when you are using HTTP Post with standard HTTP header "application/x-www-form-urlencoded" but if you are uploading files (correspondingly using ""multipart/form-data") Django gives you control over streamed chunks of files using Middleware classes: http://docs.djangoproject.com/en/dev/topics/http/middleware/

Resources