|
我写了一个httpPost的方法,在loadrunner的vusergen里调用成功,能看到System.out.println("Mflag=" + flag);
在controller里passedTransaction ,failedTransaction ,Errors都为空的。reponeseTime 等都没数据。
谁能帮帮我,搞了一天了。- package com.baomihua;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- import java.net.HttpURLConnection;
- import java.net.MalformedURLException;
- import java.net.URL;
- public class HttpRequest {
- public boolean sendPostRequest(String data,String path) {
- boolean flag = false;
- // Build parameter string
- try {
- // Send the request
- URL url = new URL(path);
- if(url!=null){
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- conn.setConnectTimeout(3000);
-
- conn.setDoOutput(true);
-
- OutputStreamWriter writer = new OutputStreamWriter(
- conn.getOutputStream());
- // write parameters
- writer.write(data);
- writer.flush();
-
- // Get the response
- int responseCode = conn.getResponseCode();
- if (responseCode == 200) {
- StringBuffer answer = new StringBuffer();
- BufferedReader reader = new BufferedReader(
- new InputStreamReader(conn.getInputStream()));
- String line;
- while ((line = reader.readLine()) != null) {
- answer.append(line);
- }
- writer.close();
- reader.close();
- if (!answer.toString().equals("")) {
- flag = true;
- }
- // Output the response
- System.out.println("Mflag=" + flag);
- }
- }
- } catch (MalformedURLException ex) {
- ex.printStackTrace();
- } catch (IOException ex) {
- System.out.println("连接超时");
- ex.printStackTrace();
-
- }
- return flag;
- }
- }
复制代码 |
|