相关疑难解决方法(0)

Java - 通过POST方法轻松发送HTTP参数

我成功地使用此代码HTTP通过GET方法发送 带有一些参数的请求

void sendRequest(String request)
{
    // i.e.: request = "http://example.com/index.php?param1=a&param2=b&param3=c";
    URL url = new URL(request); 
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();           
    connection.setDoOutput(true); 
    connection.setInstanceFollowRedirects(false); 
    connection.setRequestMethod("GET"); 
    connection.setRequestProperty("Content-Type", "text/plain"); 
    connection.setRequestProperty("charset", "utf-8");
    connection.connect();
}
Run Code Online (Sandbox Code Playgroud)

现在我可能需要通过POST方法发送参数(即param1,param2,param3),因为它们非常长.我想在该方法中添加一个额外的参数(即String httpMethod).

如何能够尽可能少地更改上面的代码,以便能够通过GET或发送参数POST

我希望改变

connection.setRequestMethod("GET");
Run Code Online (Sandbox Code Playgroud)

connection.setRequestMethod("POST");
Run Code Online (Sandbox Code Playgroud)

本来可以做到的,但参数仍然是通过GET方法发送的.

HttpURLConnection任何方法可以帮助吗?有没有有用的Java构造?

任何帮助将非常感谢.

java post http httpurlconnection

310
推荐指数
8
解决办法
78万
查看次数

如何使用Android在Request上发送JSON对象?

我想发送以下JSON文本

{"Email":"aaa@tbbb.com","Password":"123456"}
Run Code Online (Sandbox Code Playgroud)

到Web服务并阅读响应.我知道如何阅读JSON.问题是上述JSON对象必须以变量名发送jason.

我怎么能从android做到这一点?有哪些步骤,例如创建请求对象,设置内容标题等.

post android json httprequest

115
推荐指数
5
解决办法
23万
查看次数

在android中通过http post方法发送json对象

已提供的NOT DUPLICATE.Link是旧版本."http客户端"已在api23中删除

我想发送json对象:

{"emailId":"ashish.bhatt@mobimedia.in","address":"Naya bans","city":"Noida","pincode":"201301","account_number":"91123546374208","bank_name":"Axis Bank","branch_name":"91123546374208","ifsc_code":"UTI0000879"}
Run Code Online (Sandbox Code Playgroud)

到网址:

http://10digimr.mobimedia.in/api/mobile_retailer/update_profile 我该怎么办?通过邮政方式?

方法:

 POST /api/mobile_retailer/update_profile
Run Code Online (Sandbox Code Playgroud)

强制关键:

{"emailId","address"}
Run Code Online (Sandbox Code Playgroud)

请求JSON:

{"emailId":"ashish.bhatt@mobimedia.in","address":"Naya bans","city":"Noida","pincode":"201301","account_number":"91123546374208","bank_name":"Axis Bank","branch_name":"91123546374208","ifsc_code":"UTI0000879"}
Run Code Online (Sandbox Code Playgroud)

响应:

{"message":"Mail Send","data":true,"status":200}
Run Code Online (Sandbox Code Playgroud)

android json http-post httprequest httpurlconnection

1
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×2

httprequest ×2

httpurlconnection ×2

json ×2

post ×2

http ×1

http-post ×1

java ×1