java - convert curl request into URLConnection -
i have curl
request:
curl -h 'accept: application/vnd.twitchtv.v3+json' -h 'authorization: oauth <access_token>' \ -x put https://api.twitch.tv/kraken/users/<bot_name>/follows/channels/<channel_name>
i need turn java urlconnection
request. have far:
string url = "https://api.twitch.tv/kraken/?oauth_token=" + bot.botoauth.substring("oauth:".length()); url obj = new url(url); httpurlconnection conn = (httpurlconnection) obj.openconnection(); conn.setrequestproperty("content-type", "application/json"); conn.setdooutput(true); conn.setrequestmethod("put"); outputstreamwriter out = new outputstreamwriter(conn.getoutputstream()); out.write("https://api.twitch.tv/kraken/users/" + bot.botname + "/follows/channels/" + gamrcorpstextfield.gettext()); out.close(); new inputstreamreader(conn.getinputstream());
any appreciated!
the url preparing open in code:
string url = "https://api.twitch.tv/kraken/?oauth_token=" + bot.botoauth.substring("oauth:".length());
does not match curl
request url:
https://api.twitch.tv/kraken/users/<bot_name>/follows/channels/<channel_name>
you appear want more this:
url requesturl = new url("https://api.twitch.tv/kraken/users/" + bot.botname + "/follows/channels/" + gamrcorpstextfield.gettext()); httpurlconnection connection = (httpurlconnection) requesturl.openconnection(); connection.setrequestmethod("put"); connection.setrequestproperty("accept", "application/vnd.twitchtv.v3+json"); connection.setrequestproperty("authorization", "oauth <access_token>"); connection.setdoinput(true); connection.setdooutput(false);
that sets "urlconnection
request" equivalent 1 curl
command issue, requested. there response code, read response headers , body, , forth via connection
object.
Comments
Post a Comment