51Testing软件测试论坛
标题:
java 脚本在vusergen运行成功,在controller不行啊。?
[打印本页]
作者:
dgjy1978
时间:
2014-1-7 17:42
标题:
java 脚本在vusergen运行成功,在controller不行啊。?
我写了一个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;
}
}
复制代码
作者:
ffwithvv
时间:
2014-1-10 16:29
controller如何设置的?
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/)
Powered by Discuz! X3.2