Changeset 1563 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2009-04-28T20:47:13+02:00 (15 years ago)
Author:
framm
Message:
  • fixed content-type headers for API requests. always use text/xml if there is payload.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r1559 r1563  
    367367                addAuth(activeConnection);
    368368
    369                 if (requestBody != null) {
     369                if (requestMethod.equals("PUT") || requestMethod.equals("POST")) {
    370370                    activeConnection.setDoOutput(true);
     371                    activeConnection.setRequestProperty("Content-type", "text/xml");
    371372                    OutputStream out = activeConnection.getOutputStream();
    372                     BufferedWriter bwr = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
    373                     bwr.write(requestBody);
    374                     bwr.flush();
    375                     out.close();
    376                 } else {
     373
    377374                    // It seems that certain bits of the Ruby API are very unhappy upon
    378375                    // receipt of a PUT/POST message withtout a Content-length header,
    379376                    // even if the request has no payload.
    380377                    // Since Java will not generate a Content-length header unless
    381                     // we use the output stream, we create one and write no data to
    382                     // it, instead of not creating one. -- fr 6-Apr-09
    383                     activeConnection.setDoOutput(true);
    384                     OutputStream out = activeConnection.getOutputStream();
     378                    // we use the output stream, we create an output stream for PUT/POST
     379                    // even if there is no payload.
     380                    if (requestBody != null) {
     381                        BufferedWriter bwr = new BufferedWriter(new OutputStreamWriter(out, "UTF-8"));
     382                        bwr.write(requestBody);
     383                        bwr.flush();
     384                    }
    385385                    out.close();
    386386                }
Note: See TracChangeset for help on using the changeset viewer.