我试图从wget的结果中提取一条线但是遇到了麻烦.这是我的wget电话:
$ wget -SO- -T 1 -t 1 http://myurl.com:15000/myhtml.html
Run Code Online (Sandbox Code Playgroud)
输出:
--18:24:12-- http://xxx.xxxx.xxxx:15000/myhtml.html
=> `-'
Resolving xxx.xxxx.xxxx... xxx.xxxx.xxxx
Connecting to xxx.xxxx.xxxx|xxx.xxxx.xxxx|:15000... connected.
HTTP request sent, awaiting response...
HTTP/1.1 302 Found
Date: Tue, 18 Nov 2008 23:24:12 GMT
Server: IBM_HTTP_Server
Expires: Thu, 01 Dec 1994 16:00:00 GMT
Location: https://xxx.xxxx.xxxx/siteminderagent/...
Content-Length: 508
Keep-Alive: timeout=10, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1
Location: https://xxx.xxxx.xxxx//siteminderagent/...
--18:24:13-- https://xxx.xxxx.xxxx/siteminderagent/...
=> `-'
Resolving xxx.xxxx.xxxx... failed: Name or service not known.
如果我这样做:
$ wget -SO- -T 1 -t 1 http://myurl.com:15000/myhtml.html …Run Code Online (Sandbox Code Playgroud) 我们正在使用以下方法创建一个由java类(Java2WS)驱动的Web服务(基于CXF):
@WebMethod
@RequestWrapper(className = "com.myproject.wrapper.MyRequestWrapper")
@ResponseWrapper(className = "com.myproject.wrapper.MyResponseWrapper")
public MyResponse verifyCode(@WebParam(name = "code") String code) {
...
return new MyResponse("Hello",StatusEnum.okay);
}
Run Code Online (Sandbox Code Playgroud)
我使用包装器来定义请求resp的元素.更详细的响应:正确的元素名称(以大写字符开头),必需元素和可选元素,...).但我不确定这是否是正确的方法(没有关于包装器的深入文档,不是吗?)
MyResponse类:
public class MyResponseWrapper {
private String result;
private ModeEnum status;
// getters and setters
}
Run Code Online (Sandbox Code Playgroud)
MyReponseWrapper类
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "myResponse")
public class MyResponseWrapper {
@XmlElement(name="Result")
private String result;
@XmlElement(name = "Status")
private StatusEnum status;
public MyResponseWrapper() {
result="fu"; // just for testing
}
// getters and setters
}
Run Code Online (Sandbox Code Playgroud)
目前我不了解Wrappers.当我返回MyReponse的一个实例时,MyResponse的数据如何被分别注入MyResponseWrapper到响应的SOAP主体?
通过测试这个Web服务,我可以看到MyResponseWrapper的实例被实例化,SOAP主体包含正确的元素,但是包含默认数据(例如:result ="fu"而不是"Hello").我预计CXF会将MyResponse的匹配数据注入MyResponseWrapper.那是错的吗?
如果这是错误的方法:在使用Java2WS时,Wat是指定生成的SOAP xml的正确方法吗?
顺便说一下:上面的源代码片段只是从我们更复杂(更多字段)类中获取的示例.
我之前从未使用过WebClient,我不确定是否应该检查来自服务器的响应,以了解上传是否成功,或者如果没有异常我是否可以将文件设置为已上传.
如果我应该检查响应我该怎么做?解析resposeHeaders属性?
提前致谢.
我有一个调用广播接收器的Activity.广播接收器等待并收听GPS.当监听器获得新点时,我想将该新点发送给Activity.如何将数据从广播接收器发送到活动?
我的Activity中需要一个监听器,等待来自Broadcast Receiver的响应.我怎样才能做到这一点?
当我尝试在本地保存文件时,响应对象返回null.我正在尝试捕获的页面需要大量的加载时间,我需要回调以在所有页面资源完全加载时通知我.我的方法是否正确?
如果不尝试在本地保存文件,则返回的响应对象不为null.
这是我的代码:
$client = Client::getInstance();
$client->getEngine()->setPath('path/to/phantomjs');
$client->isLazy();
$request = $client->getMessageFactory()->createPdfRequest('http://google.com');
$response = $client->getMessageFactory()->createResponse();
$file = 'path/binfile.pdf';
$request->setOutputFile($file);
$client->send($request, $response);
Run Code Online (Sandbox Code Playgroud)
如何实现并了解所有页面资源何时完全加载?
这就是我要的.
我成功完成了第1步和第2步(提交了POST并收到了网站的回复).
request = urllib2.Request(url, formData, headers)
response = urllib2.urlopen(request)
Run Code Online (Sandbox Code Playgroud)
但是当我试图在视图中返回它时
return response
Run Code Online (Sandbox Code Playgroud)
我得到了以下错误
Django Version: 1.3.1
Exception Type: AttributeError
Exception Value: addinfourl instance has no attribute 'has_header'
Exception Location:D:\Python27\lib\site-packages\django\utils\cache.py in patch_vary_headers
Run Code Online (Sandbox Code Playgroud)
注意:我有一个csrf错误,但我使用装饰器@csrf_exempt禁用了csrf并且错误消失了
是否可以像多部分请求一样提供HTTP多部分响应(使用Perl/PHP)?场景就像是,我想提供一个URL,它为EmployeeID提供一个参数,作为回报,响应应该包括员工的照片,最新的工资单以及姓名,年龄和地址等信息.接收端不是浏览器,但它将是一个获得此响应并稍后处理它们的程序.有关如何做到这一点的任何想法?
为了提供有关上述问题的更多信息,我必须向我的朋友提供一个URL,以便以编程方式接收回复.例如(在Perl中):
$response = $ua->request($my_url)
Run Code Online (Sandbox Code Playgroud)
我的应用程序应该不仅响应数据,还响应文件!我被要求让它返回多部分回复.
我现在不知道如何从编码本身开始.关于"多部分响应"的谷歌搜索没有返回我可以学习和开始的页面.但是,chansen的评论非常有用,以及他的代码示例https://gist.github.com/1391017.非常感谢.
我有一个ajax请求到我的服务器,我正在创建一个PDF文件.现在我想在新窗口/选项卡中显示此文件或只是下载它.我怎样才能做到这一点?
我的请求
$.ajax({
url: '/Document/CreatePDF',
type: 'POST',
data: {
docid: documentId,
dataId: array
},
traditional: true,
success: function (data) {
}
});
[HttpPost]
public FileStreamResult CreatePDF(long docid, List<long> dataId)
{
var document = _rep.LoadDocument(docid.ToString(), Server.MapPath("~/Documents/") + docid + ".xml");
var exporter = new PDFExporter(document);
MemoryStream fileStream = exporter.CreatePDF();
byte[] PdfByte = fileStream.GetBuffer();
fileStream.Flush();
fileStream.Close();
HttpContext.Response.AddHeader("content-disposition","attachment; filename=form.pdf");
return new FileStreamResult(fileStream, "application/pdf");
}
Run Code Online (Sandbox Code Playgroud) 我试图在请求的成功案例中阅读httpstatus代码e body.所以我创建了下面的代码来测试,但是我没有得到被onNext调用,我试图使用okhttp(com.squareup.okhttp.Response)和改进Response(retrofit.Response )类,但我无法使其工作.
有人可以帮我在这里阅读正文和httpstatus代码吗?我想继续使用Observables.提前致谢.
package com.app.rest;
import com.squareup.okhttp.Response;
import retrofit.GsonConverterFactory;
import retrofit.Retrofit;
import retrofit.RxJavaCallAdapterFactory;
import retrofit.http.GET;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
public class TestApiClient {
public interface Test {
@GET("/posts")
Observable<Response> getPosts();
}
public TestApiClient() {
new Retrofit.Builder()
.baseUrl("http://jsonplaceholder.typicode.com")
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build().create(Test.class).getPosts().subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<Response>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
e.toString();
}
@Override
public void onNext(Response response) {
response.toString();
}
});
}
}
Run Code Online (Sandbox Code Playgroud) 我用来避免解析遍地的服务器响应,如果它也不会改变通过计算响应的哈希值:
public class HttpClient {
protected OkHttpClient mClient = new OkHttpClient();
public String get(final URL url, final String[] responseHash)
throws IOException {
HttpURLConnection connection = new OkUrlFactory(mClient).open(url);
InputStream inputStream = null;
MessageDigest messageDigest = null;
try {
messageDigest = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
assert messageDigest != null;
try {
// Read the response.
inputStream = connection.getInputStream();
byte[] response = readFully(inputStream);
final byte[] digest = messageDigest.digest(response);
responseHash[0] = Base64.encodeToString(digest, Base64.DEFAULT);
return …Run Code Online (Sandbox Code Playgroud)