如何通过http接口使用f12b实现批量提交链接

这里我们分别叙述了如何在浏览器直接使用此接口,以及通过java和python如何使用此接口。

一、以浏览器为例

(一)提交一个指令

serverURL=http://120.79.247.23/f12Browser/http?cmd=requestACommand           #指令提交地址

username=test                                            #测试专用用户名

password=123456                                      #测试专用密码

targetURL=http://www.baidu.com               #你的目标url,这个可以修改为你指定的url

commandVersion=local_and_server          #固定值

commandAction=none                               #固定值

 

1 请求链接=serverURL+username+password+targetURL+commandVersion+commandAction

如“http://120.79.247.23/f12Browser/http?cmd=requestACommand&username=test&password=123456&targetURL=http://www.baidu.com&commandVersion=local_and_server&commandAction=none”

2 将上述链接复制并黏贴至浏览器运行,会得到下面的字符串,表明指令提交成功。其中commandID为系统分配给你的唯一标识,后续操作需要通过该ID实现。

<status>success</status><commandID>19</commandID>

若status不为success,则返回格式为

<status>error</status><msg>异常信息</msg>

(二) 查询执行情况

serverURL=http://120.79.247.23/f12Browser/http?cmd=quaryACommand           #指令查询地址

username=test                                            #测试专用用户名

password=123456                                      #测试专用密码

commandID=19                                          #指令唯一标识

 

1 请求链接=serverURL+username+password+commandID

如“http://120.79.247.23/f12Browser/http?cmd=quaryACommand&username=test&password=123456&commandID=19”

2 将上述链接复制到浏览器执行,会得到下面的字符串。其中commandStatus表明了当前指令的执行情况,finished表明该指令已执行完成,可以向服务器请求执行结果

<status>success</status>
<commandID>19</commandID>
<commandVersion>local_and_server</commandVersion>
<targetURL>http://www.baidu.com</targetURL>
<commandAction>none<commandAction/>
<commandStatus>finished</commandStatus>
<createrID>1</createrID>
<createTime>2018-06-11 14:25:10.0</createTime>
<updateTime>2018-06-11 14:25:25.0</updateTime>

3 若指令还未开始还行,则commandStatus=create,未执行完成,则commandStatus=assigned

4 若查询过程中出现异常,返回格式为:

<status>error</status><msg>异常信息</msg>

(三)获取执行结果

在浏览器中有两种方式获取结果,一是通过接口请求结果,另一种是可以直接下载结果文件。

1 通过接口请求结果

http://120.79.247.23/f12Browser/http?cmd=getAFileContent&username=test&password=123456&commandID=19

正确的结果形式:

<status>success</status><fileContent>URL对应的HTML源码</fileContent>

若发生异常:

<status>error</status><msg>异常信息</msg>

2 直接下载结果文件

http://120.79.247.23/f12Browser/http?cmd=downloadAFile&username=test&password=123456&commandID=19

 二、以java为例

这里需要用到webdriver3.7的环境

https://share.weiyun.com/5DCfA1a

(一)提交一个指令

public static void main(String[] args) {
        try{
            //1 提交指令
            String requestCommandURL = "http://120.79.247.23/f12Browser/http?cmd=requestACommand";
            DefaultHttpClient client = new DefaultHttpClient();
            HttpPost httpPost=new HttpPost(requestCommandURL);
            List<BasicNameValuePair> params=new ArrayList<BasicNameValuePair>();
            params.add(new BasicNameValuePair("username", "test"));
            params.add(new BasicNameValuePair("password", "123456"));
            params.add(new BasicNameValuePair("targetURL", "http://www.baidu.com"));
            params.add(new BasicNameValuePair("commandVersion", "local_and_server"));
            params.add(new BasicNameValuePair("commandAction", "none"));
            httpPost.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8));
            HttpResponse response = client.execute(httpPost);
            HttpEntity entity = response.getEntity();
            if(entity==null){
                System.out.println("error entity==null");
                client.close();
                return;
            }
            String results = EntityUtils.toString(entity, "UTF-8");
            System.out.println("results="+results);
            client.close();
            return;
        }catch(Exception e){
            e.printStackTrace();
            return;
        }
    }

正确执行的话应该能得到如下结果:

<status>success</status><commandID>19</commandID>

若status不为success,则返回格式为

<status>error</status><msg>异常信息</msg>

(二)查询执行情况

public static void main(String[] args) {
        try{
            //2 查询指令执行状态
            String requestCommandURL = "http://120.79.247.23/f12Browser/http?cmd=quaryACommand";
            DefaultHttpClient client = new DefaultHttpClient();
            HttpPost httpPost=new HttpPost(requestCommandURL);
            List<BasicNameValuePair> params=new ArrayList<BasicNameValuePair>();
            params.add(new BasicNameValuePair("username", "test"));
            params.add(new BasicNameValuePair("password", "123456"));
            params.add(new BasicNameValuePair("commandID", "19"));
            httpPost.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8));
            HttpResponse response = client.execute(httpPost);
            HttpEntity entity = response.getEntity();
            if(entity==null){
                System.out.println("error entity==null");
                client.close();
                return;
            }
            String results = EntityUtils.toString(entity, "UTF-8");
            System.out.println("results="+results);
            client.close();
            return;
        }catch(Exception e){
            e.printStackTrace();
            return;
        }
        //3 获取执行结果
    }

正确执行的话应该能得到如下结果:

<status>success</status>
<commandID>19</commandID>
<commandVersion>local_and_server</commandVersion>
<targetURL>http://www.baidu.com</targetURL>
<commandAction>none<commandAction/>
<commandStatus>finished</commandStatus>
<createrID>1</createrID>
<createTime>2018-06-11 14:25:10.0</createTime>
<updateTime>2018-06-11 14:25:25.0</updateTime>

若指令还未开始还行,则commandStatus=create,未执行完成,则commandStatus=assigned

若查询过程中出现异常,返回格式为:

<status>error</status><msg>异常信息</msg>

(三)获取执行结果

public static void main(String[] args) {
        try{
            //3 获取执行结果
            String requestCommandURL = "http://120.79.247.23/f12Browser/http?cmd=getAFileContent";
            DefaultHttpClient client = new DefaultHttpClient();
            HttpPost httpPost=new HttpPost(requestCommandURL);
            List<BasicNameValuePair> params=new ArrayList<BasicNameValuePair>();
            params.add(new BasicNameValuePair("username", "test"));
            params.add(new BasicNameValuePair("password", "123456"));
            params.add(new BasicNameValuePair("commandID", "19"));
            httpPost.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8));
            HttpResponse response = client.execute(httpPost);
            HttpEntity entity = response.getEntity();
            if(entity==null){
                System.out.println("error entity==null");
                client.close();
                return;
            }
            String results = EntityUtils.toString(entity, "UTF-8");
            System.out.println("results="+results);
            client.close();
            return;
        }catch(Exception e){
            e.printStackTrace();
            return;
        }
    }

正确的结果形式:

<status>success</status><fileContent>URL对应的HTML源码</fileContent>

若发生异常:

<status>error</status><msg>异常信息</msg>

 

三、以python为例

(一)提交一个指令

#!/usr/bin/python
import urllib.request
import urllib.parse

post_data = urllib.parse.urlencode({
    'cmd':'requestACommand',
    'targetURL':'http://www.baidu.com',
    'username':'test',
    'password':'123456',
    'commandVersion':'local_and_server',
    'commandAction':'none'
}).encode('utf-8')
requrl = "http://120.79.247.23/f12Browser/http"
req = urllib.request.Request(url = requrl, data = post_data)
print(urllib.request.urlopen(req).read().decode('utf-8'))

正确执行的话应该能得到如下结果:

<status>success</status><commandID>19</commandID>

若status不为success,则返回格式为

<status>error</status><msg>异常信息</msg>

(二)查询执行情况

#!/usr/bin/python
import urllib.request
import urllib.parse

post_data = urllib.parse.urlencode({
    'cmd':'quaryACommand',
    'username':'test',
    'password':'123456',
    'commandID':'19'
}).encode('utf-8')
requrl = "http://120.79.247.23/f12Browser/http"
req = urllib.request.Request(url = requrl, data = post_data)
print(urllib.request.urlopen(req).read().decode('utf-8'))

正确执行的话应该能得到如下结果:

<status>success</status>
<commandID>19</commandID>
<commandVersion>local_and_server</commandVersion>
<targetURL>http://www.baidu.com</targetURL>
<commandAction>none<commandAction/>
<commandStatus>finished</commandStatus>
<createrID>1</createrID>
<createTime>2018-06-11 14:25:10.0</createTime>
<updateTime>2018-06-11 14:25:25.0</updateTime>

若指令还未开始还行,则commandStatus=create,未执行完成,则commandStatus=assigned

若查询过程中出现异常,返回格式为:

<status>error</status><msg>异常信息</msg>

(三)获取执行结果

#!/usr/bin/python
import urllib.request
import urllib.parse

post_data = urllib.parse.urlencode({
    'cmd':'getAFileContent',
    'username':'test',
    'password':'123456',
    'commandID':'19'
}).encode('utf-8')
requrl = "http://120.79.247.23/f12Browser/http"
req = urllib.request.Request(url = requrl, data = post_data)
print(urllib.request.urlopen(req).read().decode('utf-8'))

正确的结果形式:

<status>success</status><fileContent>URL对应的HTML源码</fileContent>

若发生异常:

<status>error</status><msg>异常信息</msg>

 

posted @ 2018-06-11 14:44  布兰姥爷  阅读(1383)  评论(0编辑  收藏  举报