Using URL to connect to webservice through Java -
i using jira rest api pull issues created in jira . when enter url [ http://example.com/rest/api/2/search?jql=project=demo , issuetype=bug&fields=summary,priority ] in browser , getting issues , bugs , along fields summary , priority . when try use in java application , not getting same output , getting issues created .my doubt how encode url in java application . used urlencoder.encode(string s,string enc), not helpful in encoding url . idea on how encode url , cause not getting response , got in browser ??
before constructing url have segregate individual querystring values , encode following way...
import java.io.unsupportedencodingexception; import java.net.urlencoder; public class urlencodetest { public static void main(string[] args) throws unsupportedencodingexception { string baseurl="http://example.com"; string finalurl=baseurl + "?a=" + encode("this is") + "&b=" + encode(":url encoding:"); system.out.println(finalurl); } public static string encode(string str) throws unsupportedencodingexception{ return urlencoder.encode(str,"utf-8"); } }
Comments
Post a Comment