import java.io.IOException;
import com.squareup.okhttp.MediaType;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.RequestBody;
import com.squareup.okhttp.Response;
public class Test {
public static void main(String args[]) throws IOException {
OkHttpClient client = new OkHttpClient();
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
RequestBody body = RequestBody.create(mediaType, "source=en&q=Hello%2C%20world!&target=es");
Request request = new Request.Builder().url("https://google-translate1.p.rapidapi.com/language/translate/v2")
.post(body).addHeader("x-rapidapi-host", "google-translate1.p.rapidapi.com")
.addHeader("x-rapidapi-key", "ea255af93fmsh4ac35f6a83472adp1b5328jsne60af6a2b885")
.addHeader("accept-encoding", "application/gzip")
.addHeader("content-type", "application/x-www-form-urlencoded")
.build();
Response response = client.newCall(request).execute();
System.out.println(response.message());
}
}
Join in the discussion - add comment below:
same here 403 error very disappointing
Hey folks, could you try removing the
.addHeader("accept-encoding", "application/gzip")
from the request? We’ve been noticing some issues with a few APIs on the platform that utilize gzip encoding.same error here. i receive 403 error on my first use of api endpoint.
same error here. i receive 403 error on my first use of api endpoint.