代刷网商品怎么使用postjs提交post请求

&&&&& 在Android中,提供了标准Java接口HttpURLConnection和Apache接口HttpClient,为客户端HTTP编程提供了丰富的支持。
  在HTTP通信中使用最多的就是GET和POST了,GET请求可以获取静态页面,也可以把参数放在URL字符串的后面,传递给服务器。POST与GET的不同之处在于POST的参数不是放在URL字符串里面,而是放在HTTP请求数据中。
  本文将使用标准Java接口HttpURLConnection,以一个实例演示如何使用POST方式向服务器提交数据,并将服务器的响应结果显示在Android客户端
1.Android中实现
activity_main.xml部分
&RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" &
android:id="@+id/lblPostResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/butPost"
android:layout_centerHorizontal="true"
android:text="提交结果" /&
android:id="@+id/butPost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="25dp"
android:text="提交测试" /&
&/RelativeLayout&
//import部分
//import部分
import android.os.B
import android.app.A
import android.view.M
import android.view.V
import android.widget.B
import android.widget.TextV
import android.widget.T
import android.util.Log;
import java.io.InputS
import java.util.HashM
import java.util.M
import java.util.Date;
import java.text.SimpleDateF
//public class MainActivity extends Activity& 部分
private Button m_butP
m_butPost=(Button)findViewById(R.id.butPost);
m_butPost.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
butPost_OnClick(v);
//提交测试
private void butPost_OnClick(View v){
//请求参数键-值对
String strRecSmsMsg="收短信测试";
RecSmsToPost(strRecSmsMsg);
openToast("提交测试完成");
//收到短信 后 提交
private void RecSmsToPost(String strRecSmsMsg){
String strNowDateTime=getNowDateTime("yyyy-MM-dd|HH:mm:ss");//当前时间
Map&String,String& params = new HashMap&String,String&();
params.put("RECSMSMSG", strRecSmsMsg);
//params.put("name", "李四");
//服务器请求路径
String strUrlPath = "http://192.168.1.9:80/JJKSms/RecSms.php" +"?DateTime=" + strNowDateT
String strResult=HttpUtils.submitPostData(strUrlPath,params, "utf-8");
m_lblPostResult.setText(strResult);
//openToast("提交完成");
//获取当前时间
private String getNowDateTime(String strFormat){
if(strFormat==""){
strFormat="yyyy-MM-dd HH:mm:ss";
Date now = new Date();
SimpleDateFormat df = new SimpleDateFormat(strFormat);//设置日期格式
return df.format(now); // new Date()为获取当前系统时间
//弹出消息
private void openToast(String strMsg){
Toast.makeText(this, strMsg, Toast.LENGTH_LONG).show();
&HttpUtils 类部分
&新建 类文件 HttpUtils 其中代码如下:
import java.net.HttpURLC
import java.net.URL;
import java.io.OutputS
import java.io.InputS
import java.util.M
import java.io.IOE
import java.net.URLE
import java.io.ByteArrayOutputS
public class HttpUtils {
* Function
发送Post请求到服务器
params请求体内容,encode编码格式
public static String submitPostData(String strUrlPath,Map&String, String& params, String encode) {
byte[] data = getRequestData(params, encode).toString().getBytes();//获得请求体
//String urlPath = "http://192.168.1.9:80/JJKSms/RecSms.php";
URL url = new URL(strUrlPath);
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setConnectTimeout(3000);
//设置连接超时时间
httpURLConnection.setDoInput(true);
//打开输入流,以便从服务器获取数据
httpURLConnection.setDoOutput(true);
//打开输出流,以便向服务器提交数据
httpURLConnection.setRequestMethod("POST");
//设置以Post方式提交数据
httpURLConnection.setUseCaches(false);
//使用Post方式不能使用缓存
//设置请求体的类型是文本类型
httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
//设置请求体的长度
httpURLConnection.setRequestProperty("Content-Length", String.valueOf(data.length));
//获得输出流,向服务器写入数据
OutputStream outputStream = httpURLConnection.getOutputStream();
outputStream.write(data);
int response = httpURLConnection.getResponseCode();
//获得服务器的响应码
if(response == HttpURLConnection.HTTP_OK) {
InputStream inptStream = httpURLConnection.getInputStream();
return dealResponseResult(inptStream);
//处理服务器的响应结果
} catch (IOException e) {
//e.printStackTrace();
return "err: " + e.getMessage().toString();
return "-1";
* Function
封装请求体信息
params请求体内容,encode编码格式
public static StringBuffer getRequestData(Map&String, String& params, String encode) {
StringBuffer stringBuffer = new StringBuffer();
//存储封装好的请求体信息
for(Map.Entry&String, String& entry : params.entrySet()) {
stringBuffer.append(entry.getKey())
.append("=")
.append(URLEncoder.encode(entry.getValue(), encode))
.append("&");
stringBuffer.deleteCharAt(stringBuffer.length() - 1);
//删除最后的一个"&"
} catch (Exception e) {
e.printStackTrace();
return stringB
* Function
处理服务器的响应结果(将输入流转化成字符串)
inputStream服务器的响应输入流
public static String dealResponseResult(InputStream inputStream) {
String resultData = null;
//存储处理结果
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byte[] data = new byte[1024];
int len = 0;
while((len = inputStream.read(data)) != -1) {
byteArrayOutputStream.write(data, 0, len);
} catch (IOException e) {
e.printStackTrace();
resultData = new String(byteArrayOutputStream.toByteArray());
return resultD
2.服务器端的准备
  在服务器端我采用wamp方式,当然其它方式也可以。 创建RecSms.php 文件 内容如下:
require_once ('Log/LogHelper.php');
echo "你好" . "post &/br&";
foreach($_REQUEST as $k=&$v){
echo $k;echo "--";
echo $v;echo "&/br&";
WriteLog('你好 RecSms.php ---------');
foreach($_POST as $k=&$v){
WriteLog( $k .'--' .$v);
foreach($_GET as $k=&$v){
WriteLog( $k .'--' .$v);
将提交的数据写入Log\Log.php文件中。
其中LogHelper.php 为写日志文件,代码文件如下:
function WriteLog($msg){
$fp = fopen("Log\Log.php", "a");//文件被清空后再写入
date_default_timezone_set('asia/chongqing');
$time=date("H:i:s",strtotime("now"));
$flag=fwrite($fp, $time ."
fclose($fp);
&所有代码已写好。
&开启 wamp ,在Android中点击 提交测试 则 在Log.php文件写入提交的数据
阅读(...) 评论()查看: 11800|回复: 111
多线程代理验证代理POST GET提交,刷票、刷访问、多用途
阅读权限50
签到天数:5 天结帖率: (1/1)
是否带模块:
调用了模块
卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍
1.自动从网络上获取代理IP
2.多线程自动验证代理IP是否可用
3.多线程提交,速度翻倍~~
卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍
请自行测试
卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍
卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍卍
特别声明:不接受任何口水、吐槽仅供分享.
09:12 上传
点击文件名下载附件
下载积分: 精币 -1 枚
678.97 KB, 下载次数: 1614, 下载积分: 精币 -1 枚
模块源码打包
拒绝任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论,本站内容均为会员发表,并不代表精易立场!
揭阳精易科技有限公司申明:我公司所有的培训课程版权归精易所有,任何人以任何方式翻录、盗版、破解本站培训课程,我们必将通过法律途径解决!
公司简介:揭阳市揭东区精易科技有限公司致力于易语言教学培训/易语言学习交流社区的建设与软件开发,多年来为中小企业编写过许许多多各式软件,并把多年积累的开发经验逐步录制成视频课程供学员学习,让学员全面系统化学习易语言编程,少走弯路,减少对相关技术的研究与摸索时间,从而加快了学习进度!
防范网络诈骗,远离网络犯罪
违法和不良信息举报电话,QQ: ,邮箱:@b.qq.com
Powered by
X3.2 揭阳市揭东区精易科技有限公司
粤公网安备 25代刷网商品怎么使用post提交_百度知道
代刷网商品怎么使用post提交
代刷网商品怎么使用post提交
答题抽奖
首次认真答题后
即可获得3次抽奖机会,100%中奖。
post提交不实用吧。。。
调用接口使用
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。

我要回帖

更多关于 post异步提交 的文章

 

随机推荐