[Developers] Java and mql write service
Dae Park
daepark at metaweb.com
Tue Feb 19 09:24:58 UTC 2008
Do you have the message detail (JSON response) of the 400 response
you are getting?
Make sure you are doing a POST and your post parameter looks like:
queries={'qname':{'query':{...}}}
-dae
On Feb 18, 2008, at 7:07 PM, Christian Hirsch wrote:
> Hi All,
>
> I am trying to access the write API using Java, but somehow I
> always get an error.
> Sending read and login requests works just fine, however when I'm
> sending write requests I'm always getting '400 bad request'. I'm
> not very familiar with http requests in java... could there be
> something wrong with the request header? or the credentials? -
> maybe someone has some working example code?
>
> this is the code I'm using:
>
> query = "{\"create\":\"unless_exists\",\"id\":null,\"type\":\"/
> common/topic\", \"name\":\"test_xy\"}";
> String envelope = "{\"qname\":{\"query\":" +query+ "}}";
> String data = URLEncoder.encode(envelope, "UTF-8");
>
> URL url = new URL("http://sandbox.freebase.com/api/service/mqlwrite");
> URLConnection conn = url.openConnection();
> conn.setDoInput(true);
> conn.setDoOutput(true);
>
> String credentials = "metaweb-user=..."; // value of the Set-Cookie
> from the login response
> conn.setRequestProperty("Cookie", credentials);
> conn.setRequestProperty("X-Metaweb-Request", "True");
> conn.setRequestProperty("Content-type", "application/x-www-form-
> urlencoded");
>
> OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream
> ());
> wr.write(data);
> wr.flush();
>
> BufferedReader rd = new BufferedReader(new InputStreamReader
> (conn.getInputStream()));
> //write the response to a JSON object...
> wr.close();
> rd.close();
>
>
> Thanks,
> Christian
> _______________________________________________
> Developers mailing list
> Developers at freebase.com
> http://lists.freebase.com/mailman/listinfo/developers
More information about the Developers
mailing list