向指定URL傳送POST,GET請求

2021-08-03 05:18:41 字數 887 閱讀 5250

/**

* 向指定 url 傳送post方法的請求

* *@param url

* 傳送請求的 url

*@param param

* 請求引數,請求引數應該是 name1=value1&name2=value2 的形式。

*@return 所代表遠端資源的響應結果

*/public

static string sendpost(string url, string param)

} catch (exception e)

//使用finally塊來關閉輸出流、輸入流

finally

if(in!=null)

}catch(ioexception ex)

}return result;

} /**

* post方法 引數為json物件

*@param url

*@param jsonparam 封裝為json物件的引數;

*@return

*/public

static string sendpost(string url,jsonobject jsonparam)

system.out.println(sb);

reader.close();

// 斷開連線

connection.disconnect();

return sb.tostring();

} catch (malformedurlexception e) catch (unsupportedencodingexception e) catch (ioexception e)

}

向目的url傳送post請求

closeablehttpclient 請求直接上 可以寫在工具類中,直接多次呼叫。response返回的值使用json格式 code,message等等 public static jsonobject sendpostrequest string url,string param param.t...

Window向指定視窗傳送訊息

1 字元 e postmessage hwnd,wm keydown,0x4c,0 postmessage hwnd,wm keyup,0x4c,0 ee2 ctrl c keybd event vk control,0,0 0 postmessage hwnd,wm keydown,0x43,0 ...

PHP向特定URL傳送POST資料

今天工作中遇到了post資料的問題,需要向乙個特定的url傳送post資料。現將php傳送post資料的方式總結下,方便自己造福後人 方法一 http函式傳送方式 說明 data為post傳送的資料 key為引數名,val為引數值 方法二 curl post資料 php view plain cop...