robotoworks / mechanoid

Eclipse plugin providing a set of DSL's for the rapid development of Android apps
58 stars 26 forks source link

Problem with Content-Type: application/x-www-form-urlencoded #237

Closed hannesa2 closed 10 years ago

hannesa2 commented 10 years ago

Hi have to speak with a server, requiring to send with

  Content-Type: application/x-www-form-urlencoded

but till now it's not working with mechanoid With browser not works https://dl.dropboxusercontent.com/u/18016212/request_not_working.png With browser works https://dl.dropboxusercontent.com/u/18016212/request_working.png With postman works https://dl.dropboxusercontent.com/u/18016212/request_postman_working.png

I figured out in ServiceClient.java this lines with re-set of Content-type

        conn.setDoOutput(true);
        conn.setRequestMethod(method);
        conn.setRequestProperty("Content-Type", "application/json, text/json");
        applyRequestProperties(request, conn);

In my non-mechanoid (to replace) implementation it works like

    urlCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    PrintWriter out = new PrintWriter(urlConnection.getOutputStream());
    out.print(paramString);
    out.close();
    InputStream in = null;
    try {
        in = new BufferedInputStream(urlCon.getInputStream());

How to do this with mechanoid ?

Thank you !

fluxtah commented 10 years ago

Hey hannesa2,

Unfortunately I have not needed to do this yet, so I am unsure wether it would work with Mechanoid NET.

Mechanoid NET does allow you to add extra headers to your generated client, but I am not sure if HttpUrlConnection supports this since Mechanoid NET uses HttpUrlConnection under the hood.

I believe apache HttpClient is capable of these kinds of requests.

hannesa2 commented 10 years ago

pull request https://github.com/robotoworks/mechanoid/pull/239