Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. https://graph.facebook.com/me?access_token={ACCESS_TOKEN}
  2.  
  3. {"success":true}
  4.  
  5. null: HTTP/1.1 200 OK
  6. Access-Control-Allow-Origin: *
  7. Cache-Control: private, no-cache, no-store, must-revalidate
  8. Connection: keep-alive
  9. Content-Length: 16
  10. Content-Type: text/javascript; charset=UTF-8
  11. Date: Mon, 27 Mar 2017 19:53:18 GMT
  12. Expires: Sat, 01 Jan 2000 00:00:00 GMT
  13. facebook-api-version: v2.8
  14. Pragma: no-cache
  15. X-Android-Received-Millis: 1490644395774
  16. X-Android-Response-Source: NETWORK 200
  17. X-Android-Selected-Protocol: http/1.1
  18. X-Android-Sent-Millis: 1490644395542
  19. X-FB-Debug: {X-FB-DEBUG}
  20. x-fb-rev: 2916655
  21. x-fb-trace-id: {x-fb-trace-id}
  22.  
  23. {
  24. "name": "First_name Surname",
  25. "id": "123456789"
  26. }
  27.  
  28. class postRequest_runtimeTask implements Runnable
  29. {
  30. private String url;
  31. private HashMap<String, String> data;
  32. private postRequest_runtimeTask(String urlS, HashMap<String, String> dataS) {url = urlS; data = dataS;};
  33.  
  34. @Override
  35. public void run()
  36. {
  37. URL requestUrl;
  38.  
  39. try
  40. {
  41. requestUrl = new URL(url);
  42.  
  43. HttpURLConnection conn = (HttpURLConnection) requestUrl.openConnection();
  44. conn.setReadTimeout(15000);
  45. conn.setConnectTimeout(15000);
  46. conn.setRequestMethod("POST");
  47. conn.setDoInput(true);
  48. conn.setDoOutput(true);
  49.  
  50. /*
  51.  
  52. for(String key : conn.getHeaderFields().keySet())
  53. {
  54. List<String> tmp = conn.getHeaderFields().get(key);
  55.  
  56. for(String tmpval : tmp)
  57. {
  58. Log.v("Header " + key, tmpval);
  59. }
  60. }
  61. */
  62.  
  63. /* Build String from HashMap for POST-Params */
  64. StringBuilder requestDataTmp = new StringBuilder();
  65.  
  66. boolean first = true;
  67.  
  68. for(Map.Entry<String, String> entry : data.entrySet())
  69. {
  70. if(first)
  71. {
  72. first = false;
  73. }
  74. else
  75. {
  76. requestDataTmp.append("&");
  77. }
  78.  
  79. requestDataTmp.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
  80. requestDataTmp.append("=");
  81. requestDataTmp.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
  82. }
  83.  
  84. String requestData = requestDataTmp.toString();
  85.  
  86. OutputStream os = conn.getOutputStream();
  87. BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
  88. writer.write(requestData);
  89.  
  90. writer.flush();
  91. writer.close();
  92. os.close();
  93. int responseCode=conn.getResponseCode();
  94.  
  95. TEMP_BUFFER = "";
  96.  
  97. if (responseCode == HttpsURLConnection.HTTP_OK)
  98. {
  99. String line;
  100. BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream()));
  101.  
  102. while((line=br.readLine()) != null)
  103. {
  104. TEMP_BUFFER += line;
  105. }
  106. }
  107. else
  108. {
  109. //TEMP_BUFFER = "";
  110.  
  111. Log.e("HTTP RESPONSE CODE", String.valueOf(responseCode) + ", url: " + url + ", content: nn" + TEMP_BUFFER);
  112. }
  113. }
  114. catch(Exception exp)
  115. {
  116. exp.printStackTrace();
  117. }
  118. }
  119. }
  120.  
  121. Thread postRequest_runtimeTastAsync = new Thread(new postRequest_runtimeTask(url, data));
  122. postRequest_runtimeTastAsync.start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement