我有一个函数检查cookie(按名称)是否存在:
Private Function cookieExists(ByVal cName As String) As Boolean
For Each c As HttpCookie In Response.Cookies
If c.Name = cName Then Return True
Next
Return False
End Function
Run Code Online (Sandbox Code Playgroud)
我有一个以特定于应用程序的方式处理cookie的类,我想将所有与cookie相关的函数合并到这个类中.但是,如果我只是将它从aspx页面(它当前所在的位置)移动到上述类,我就无法使用此代码,因为我收到了错误:'Name' Response is not declared. 我修改了类以允许传递Response对象的引用:
Public Function cookieExists(ByVal cName As String, ByRef Response As HttpResponse) As Boolean
For Each c As HttpCookie In Response.Cookies
If c.Name = cName Then Return True
Next
Return False
End Function
Run Code Online (Sandbox Code Playgroud)
我的问题是:有更好的方法吗?
如果我将原始HTTP响应作为字符串:
HTTP/1.1 200 OK
日期:2010年5月11日星期二07:28:30 GMT
到期:-1
Cache-Control:private,max-age = 0
Content-Type:text/html; charset = UTF-8
服务器:gws
X-XSS-Protection:1; mode = block
连接:关闭
<!doctype html><html>...</html>
Run Code Online (Sandbox Code Playgroud)
有没有一种简单的方法可以将它解析为一个HttpListenerResponse对象?或者至少是某种.NET对象,所以我不必使用原始响应.
我目前正在做的是提取标题键/值对并在HttpListenerResponse上设置它们.但是有些头文件无法设置,然后我必须剪切响应的主体并将其写入OutputStream.但是身体可以被gzipped,或者它可能是一个图像,我还无法工作.并且一些响应在任何地方都包含随机字符,这看起来像编码问题.这很麻烦.
我正在获得原始响应,因为我正在使用SOCKS发送HTTP请求.我正在处理的程序基本上是一个HTTP代理,它可以通过SOCKS代理路由请求,就像Privoxy那样.
对Android应用程序开发来说是一个新手.在我的新Android应用程序中,我想显示来自webservice的一些数据.这意味着我有一个SOAP message,我需要解析SOAP响应中的数据.在iPhone应用程序中,我非常清楚解析SOAP消息响应,但在android中我不知道如何做到这一点?我在谷歌搜索了很多并获得了一些想法.但是,我对此非常困惑.任何人都可以请建议,了解SOAP请求发送/接收响应,并解析(任何最简单的方法XML format)在响应SAXParser中Android?我安装ksoap2-android-assembly-2.6.0-jar-with-dependencies.jar在我的项目中.在这里我找到了一些示例代码,我在这里发布,
import java.io.*;
import org.ksoap2.SoapEnvelope;
import org.kxml2.io.KXmlParser;
import org.xmlpull.v1.XmlPullParserException;
public class ParsingSteps
{
public static void main(String[] args)
{
try{
// String msg="<hello>World!</hello>";
String msg = "<SOAP-ENV:Envelope " + "xmlns:SOAP-ENV=\"http://
www.w3.org/2001/12/soap-envelope\" " + "xmlns:xsi=\"http://www.w3.org/
2001/XMLSchema-instance <http://www.w3.org/%0A2001/XMLSchema-instance>\""
+"xmlns:xsd=\"http://www.w3.org/2001/
XMLSchema\"& gt;" +
"<SOAP-ENV:Body>" +
"<result>" +
"<message xsi:type=\"xsd:string\">Hello World</message>" +
"</result>" +
"</SOAP-ENV:Body>" +
"</SOAP-ENV:Envelope>";
// byte[] in= msg.getBytes();
KXmlParser parser=new KXmlParser();
parser.setInput(new StringReader(msg));
SoapEnvelope soapenvelope= new SoapEnvelope
(SoapEnvelope.VER12);
//soapenvelope.parse(parser); …Run Code Online (Sandbox Code Playgroud) 我有一个奇怪的故障,我无法进行两次相同的网络通话.
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
try {
HttpResponse response = client.execute(post, new BasicHttpContext());
Run Code Online (Sandbox Code Playgroud)
我第一次运行网络调用它工作得很好,返回数据.我第二次运行网络调用(我已经在这里运行了断点)它到达HttpResponse对象,运行网络调用,但随后立即跳转到IOExceptioncatch.
该post对象具有每一次相同的数据,饼干都包括在内.
我不是任何了解服务器的人(运行drupal),但它似乎是一个服务器问题.
有人能说清楚为什么会这样吗?为什么我会被禁止第二次获取数据?
为了进一步了解事物,如果我突破响应对象,我可以看到它可能返回""而不是数据.如果这有帮助的话
05-15 11:22:34.612: E/(1094): ObjectService
05-15 11:22:34.612: E/(1094): org.apache.http.client.ClientProtocolException
05-15 11:22:34.612: E/(1094): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:557)
05-15 11:22:34.612: E/(1094): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
05-15 11:22:34.612: E/(1094): at com.fivepoints.service.ObjectService.getObject(ObjectService.java:121)
05-15 11:22:34.612: E/(1094): at com.fivepoints.model.team.TeamView$ActivityListTask.doInBackground(TeamView.java:94)
05-15 11:22:34.612: E/(1094): at com.fivepoints.model.team.TeamView$ActivityListTask.doInBackground(TeamView.java:1)
05-15 11:22:34.612: E/(1094): at android.os.AsyncTask$2.call(AsyncTask.java:185)
05-15 11:22:34.612: E/(1094): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
05-15 11:22:34.612: E/(1094): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
05-15 11:22:34.612: …Run Code Online (Sandbox Code Playgroud) 可能重复:
使用PHP curl如何获得400响应的响应主体
当使用PHP的curl_exec调用RESTful API时,文档说http://php.net/manual/en/function.curl-exec.php
成功时返回TRUE,失败时返回FALSE.但是,如果设置了CURLOPT_RETURNTRANSFER选项,它将在成功时返回结果,在失败时返回FALSE.
当curl_exec失败时,它返回false.但是,远程服务器可能已尝试返回有用的消息以使用该错误.当它只返回false时,如何使用curl_exec访问此消息?
例如,远程API可能会返回此消息和HTTP 400状态代码:
{"Items":[{"Field":"FirstName","Description":"FirstName is required and cannot be null."}]}
Run Code Online (Sandbox Code Playgroud)
目前我无法读取已返回的此错误消息,而是我得到的所有内容都是false.我也看过curl_info.我确实有返回传输.
在C#中我会使用该exception.Response.GetResponseStream方法并编写:
private static string Post(WebClient client, string uri, string postData)
{
string response = string.Empty;
try
{
response = client.UploadString(uri, "POST", postData);
}
catch (WebException ex)
{
var stream = ex.Response.GetResponseStream(); // here
if (stream != null)
{
using (var reader = new StreamReader(stream))
{
response = reader.ReadToEnd();
}
}
}
return response;
}
Run Code Online (Sandbox Code Playgroud)
如何在PHP中完成?curl_exec是正确的方法还是应该使用别的东西?
我正在使用发送HTTP请求的Sharefile API并获得各自的答案.它们是通过URL制作的,并始终使用相同的功能.这里是.
Private Function InvokeShareFileOperation(ByVal requestUrl As String) As JObject
Dim request As HttpWebRequest = WebRequest.Create(requestUrl)
Dim response As HttpWebResponse = request.GetResponse()
Dim reader As StreamReader = New StreamReader(response.GetResponseStream())
Dim json As String = reader.ReadToEnd()
response.Close()
Return JObject.Parse(json)
End Function
Run Code Online (Sandbox Code Playgroud)
由于某些操作有点长,我需要以某种方式跟踪他们正在进行的进度并且不知道如何进行.后来我打算使用这个进度并从中创建一个进度条.
(编辑)顺便说一句,这是占用大部分时间的第二个代码行(下面),即跟踪操作.
Dim response As HttpWebResponse = request.GetResponse()
Run Code Online (Sandbox Code Playgroud) 这个问题与我刚才问过的问题非常相似:我可以使用Google搜索结果来显示最终的重定向网址吗?,但现在问题是Django特有的.
我的网站的网页网址使用以下格式:
www.mysite.com/id/pretty_title
Run Code Online (Sandbox Code Playgroud)
首页链接到这些页面,但href实际上包含一些参数:
www.mysite.com/id/?some_ugly_parameters_to_let_me_know_what_search_it_is_from
Run Code Online (Sandbox Code Playgroud)
然后重定向到
www.mysite.com/id/pretty_title
Run Code Online (Sandbox Code Playgroud)
显示页面.
我的问题是 Google的搜索结果显示该页面的链接是丑陋的网址,而不是漂亮的重定向网址.
我所学到的是我需要提供规范链接.但是,当丑陋的网页从未真正存在时,我怎么能这样做,至少不是我写的那个?
服务器端发生的事情是丑陋网址的视图会重定向:
return HttpResponseRedirect(pretty_url)
Run Code Online (Sandbox Code Playgroud) 我使用以下Ruby代码段下载8.9MB文件.
require 'open-uri'
require 'net/http'
require 'uri'
def http_download_no_progress_bar(uri, filename)
uri.open(read_timeout: 500) do |file|
open filename, 'w' do |io|
file.each_line do |line|
io.write line
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
我想添加progressbar gem来可视化下载过程:
require 'open-uri'
require 'progressbar'
require 'net/http'
require 'uri'
def http_download_with_progressbar(uri, filename)
progressbar = nil
uri.open(
read_timeout: 500,
content_length_proc: lambda { |total|
if total && 0 < total.to_i
progressbar = ProgressBar.new("...", total)
progressbar.file_transfer_mode
end
},
progress_proc: lambda { |step|
progressbar.set step if progressbar
}
) do |file|
open …Run Code Online (Sandbox Code Playgroud) 我正在玩Microsoft PowerApps和Microsoft Flow.我试图弄清楚如何从PowerApps进行API调用,并将结果(状态和正文)返回到我的应用程序中的文本框等字段.
我可以通过Flow发出HTTP请求并将它们放在静态文件中,例如excel电子表格等.我也可以通过PowerApps控件(如按钮)进行调用,但我知道如何处理它是将它返回到excel文件,当我真的想将它返回到文本框或文本区域时.
我想在HttpResponseMessage上设置Content-Encoding,我不能为我的生活找到方法.鉴于此WebApi动作
public HttpResponseMessage Get()
{
byte[] tile = GetTile();
var result = new HttpResponseMessage(HttpStatusCode.OK) {Content = new ByteArrayContent(tile)};
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-protobuf");
return result;
}
Run Code Online (Sandbox Code Playgroud)
如何将标头上的Content-Encoding设置为gzip?
result.Content.Headers.ContentEncoding
Run Code Online (Sandbox Code Playgroud)
是只读的.
httpresponse ×10
android ×2
c# ×2
apache ×1
api ×1
asp.net ×1
buffer ×1
class ×1
cookies ×1
curl ×1
django ×1
drupal ×1
encoding ×1
getjson ×1
http-error ×1
httplistener ×1
httprequest ×1
java ×1
json ×1
open-uri ×1
php ×1
powerapps ×1
progress-bar ×1
proxy ×1
ruby ×1
soap ×1
socks ×1
vb.net ×1
xml-parsing ×1