标签: httpclient

html src隐藏了

尝试使用HttpClient阅读网页.但是一些html隐藏了一些js魔法,尝试点击这个页面上的查看源http://uc.worldoftanks.eu/uc/accounts/#wot&at_search=a 任何想法如何让HttpClient返回"完整"的HTML页面?

html javascript java hidden httpclient

0
推荐指数
1
解决办法
168
查看次数

HttpClient表单URL包含没有值的参数

需要传递没有值的get参数而没有"="符号来使用外部API.网址是

http://example.com/Service/v1/service.ashx?methodName&name=val&blablabla

正如您所看到的,第一个参数是要在服务器上调用的方法(methodName)的名称,它没有任何值,也没有"=".我想以"正确"的方式形成参数,但目前形成如下:

    List<NameValuePair> params = new LinkedList<NameValuePair>();
    params.add(new BasicNameValuePair("name", "val"));
    params.add(new BasicNameValuePair("name1", "val1"));

    String paramString = URLEncodedUtils.format(params, "utf-8");

    HttpClient client = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(getEndpointUrl() + "?methodName&" + paramString);
Run Code Online (Sandbox Code Playgroud)

问题出在使用串联的最后一行(而不是常规的params转换).将"methodName"作为名称添加到params并将null作为值添加到结果URL中的"methodName =".服务器不理解这种表示法.

java web-services httpclient

0
推荐指数
1
解决办法
1159
查看次数

AndroidHttpClient和Cookies

使用带有cookie的AndroidHttpClient给我混合200 ok和403禁止响应.我不确定我做错了什么.

我以下列方式使用AndroidHttpClient:

我有几个后台线程类,每个类都执行以下操作:

HttpGet get...
HttpClient client = AndroidHttpClient.newInstance("Android");
HttpContext http_context = HttpSupport.getHttpContextInstance(); 
CookieStore cookie_store = HttpSupport.getCookieStoreInstance();
http_context.setAttribute(ClientContext.COOKIE_STORE, cookie_store);
client.execute(
Run Code Online (Sandbox Code Playgroud)

HttpSupport是一个包含两个静态字段的类; 一个CookieStore和一个HttpContext:

public class HttpSupport {

private static HttpContext _context;
private static CookieStore _cookieStore;

public static synchronized HttpContext getHttpContextInstance() {
    if (_context == null) {
        _context = new BasicHttpContext();
    }
    return _context;
}

public static synchronized CookieStore getCookieStoreInstance() {
    if (_cookieStore == null) {
        _cookieStore = new BasicCookieStore();
    }
    return _cookieStore;
}

}
Run Code Online (Sandbox Code Playgroud)

在应用程序中有多个AndroidHttpClient实例可以吗?我是否正确存储了cookie?

cookies android httpclient httpcontext

0
推荐指数
1
解决办法
3556
查看次数

如何使用多个参数调用Post api

如何使用HttpClient调用具有多个参数的Post方法?

我使用以下代码与一个参数:

var paymentServicePostClient = new HttpClient();
paymentServicePostClient.BaseAddress = 
                  new Uri(ConfigurationManager.AppSettings["PaymentServiceUri"]);

PaymentReceipt payData = SetPostParameter(card);
var paymentServiceResponse = 
   paymentServicePostClient.PostAsJsonAsync("api/billpayment/", payData).Result;
Run Code Online (Sandbox Code Playgroud)

我需要添加另一个参数userid.如何将参数与'postData'一起发送?

WebApi POST方法原型:

public int Post(PaymentReceipt paymentReceipt,string userid)
Run Code Online (Sandbox Code Playgroud)

c# httpclient asp.net-web-api

0
推荐指数
3
解决办法
2万
查看次数

http客户端冻结在Windows窗体应用程序中

我正在关注这个例子,它可以在一个控制台应用程序中运行,但后来我在一个Windows窗体应用程序中尝试了它并且它会在命中行时await client.GetAsync("api/branches/1035") 如何不同?

控制台代码(这是有效的):

static void Main()
    {
        RunAsync().Wait();
    }

    static async Task RunAsync()
    {
        using (var client = new HttpClient())
        {
            client.BaseAddress = new Uri("http://localhost:49358/");

           client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            HttpResponseMessage response = await client.GetAsync("api/branches/1035");

            if (response.IsSuccessStatusCode)
            {
                branch branch = await response.Content.ReadAsAsync<branch>();
                Console.WriteLine("{0}\t${1}", branch.Id, branch.Color);
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

当它击中时它会被冻结 await client.GetAsync("api/branches/1035")

private void button1_Click(object sender, EventArgs e)
    {
        RunAsync().Wait();
    }

    static async Task RunAsync()
    {
        using (var client = new HttpClient())
        {
            client.BaseAddress = new Uri("http://localhost:49358/");
            client.DefaultRequestHeaders.Accept.Clear(); …
Run Code Online (Sandbox Code Playgroud)

c# httpclient async-await asp.net-web-api

0
推荐指数
1
解决办法
2338
查看次数

HttpClient 在 GetStringAsync 方法上冻结

我有这个 c# MVC 代码,它与 GetAsync 和 GetPost 方法一起工作得很好,但是当使用 GetStringAsync 时,它在该行冻结:

version = await client.GetStringAsync("/API/Version");
Run Code Online (Sandbox Code Playgroud)

驱动程序代码:

Task<string>[] tasks = new Task<string>[count];
for (int i = 0; i < count; i++)
{
    tasks[i] = MyHttpClient.GetVersion(port, method);
}
Task.WaitAll(tasks);
string[] results = new string[tasks.Length];
for(int i=0; i<tasks.Length; i++)
{
    Task<string> t = (Task<string>)(tasks[i]);
    results[i] = (string)t.Result;
}
Run Code Online (Sandbox Code Playgroud)

HttpCilent 代码:

public static async Task<string> GetVersion(int port, string method)
{
    try
    {
        var client = new HttpClient();
        client.BaseAddress = new Uri("http://localhost:" + port);
        string version …
Run Code Online (Sandbox Code Playgroud)

c# httpclient

0
推荐指数
1
解决办法
4225
查看次数

如何从HttpClient获取json文件?

我正在尝试从 获取json文件HttpClient,但在添加时出现错误.subscribe

进口:

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders, HttpClientModule } from '@angular/common/http';
import { HttpModule, Request, Response, Headers, Http } from '@angular/http';
import { Observable } from 'rxjs';
Run Code Online (Sandbox Code Playgroud)

我的代码:

在此处输入图片说明

当我添加.subscribe(图像中标记为黄色)时,出现以下错误。这是什么意思?

Object { _body: error, status: 0, ok: false, statusText: "", headers: Object, type: 3, url: null }

authentication json response httpclient angular

0
推荐指数
1
解决办法
2万
查看次数

Angular:HttpClient服务和Observable自定义类型

我的getHeroes函数应该返回Hero[]Objects,但是我无法访问它的方法.难道我做错了什么 ?

hero.ts

export class Hero {
  id: number;
  name: string;

  getName(): string {
    return this.name;
  }
}
Run Code Online (Sandbox Code Playgroud)

heroes.service.ts

getHeroes (): Observable<Hero[]> {
    return this.http.get<Hero[]>(this.heroesUrl)
      .pipe(
        catchError(this.handleError('getHeroes', []))
      );
  }
Run Code Online (Sandbox Code Playgroud)

heroes.component.ts

getHeroes(): void {
  this.heroesService.getHeroes()
    .subscribe(heroes => {
      this.heroes = heroes;
      this.heroes.forEach((hero) => console.log(hero));
      this.heroes.forEach((hero) => console.log(hero.getName())); //ERROR here
    });
}
Run Code Online (Sandbox Code Playgroud)

ERROR TypeError: hero.getName is not a function在最后一行得到了一个.

这是一个实时版本Live链接

httpclient typescript angular

0
推荐指数
1
解决办法
223
查看次数

C# 的 HttpClient ReadAsStreamAsync

我在使用 C# 的 HttpClient ReadAsStreamAsync 下载 400MB+ 文件时遇到问题 - 问题是从 427724800 中仅读取了大约 213864187 个字节,然后

read = await stream.ReadAsync(buffer, 0, buffer.Length, token)
Run Code Online (Sandbox Code Playgroud)

没有明显原因一直返回0。

有人遇到过类似的问题吗?

using (var stream = await response.Content.ReadAsStreamAsync()) {
    var totalRead = 0L;
    var buffer = new byte[4096];                            
    var moreToRead = true;

    const int CHUNK_SIZE = 4096;
    var fileStream = File.Create(filename, CHUNK_SIZE);                            
    int bytesRead;
        do {
        token.ThrowIfCancellationRequested();

        var read = await stream.ReadAsync(buffer, 0, buffer.Length, token);

        if (read == 0) {
            moreToRead = false;
            this.Percentage = 100;
            if (fileStream != …
Run Code Online (Sandbox Code Playgroud)

c# httpclient

0
推荐指数
1
解决办法
1679
查看次数

为什么 Angular HTTPClient 在这种情况下重复其余调用两次?

我有一个使用 Rest API 的 Angular 服务,但是当我检查网络和后端时,我发现 API 每次都调用了两次:

这是我的服务代码:

getAllUsers():Observable<any>{
    return this.http.get(this.mainConfigService.getUsersUrl()).pipe(
        map(this.extractData));
}

private extractData(res: Response) {
        let body = res;
        return body || { };
}
Run Code Online (Sandbox Code Playgroud)

在我的组件中,我调用了这个服务:

  getAllUser(){
    let users : User[] = [];
    this.userService.getAllUsers().subscribe(data=>{
      this.usersList=data;
      data.forEach( (element) => {
        users.push(
               {
                fullName: element.fullName,
                firstName:element.firstName,
                lastName:element.lastName,
                mail:element.mail,
                idNumber:element.idNumber,
                accountExpiresDateTime:element.accountExpiresDateTime,
                role:element.role
             }
             );
      });
      this.dataSource = new MatTableDataSource(users);
      this.dataSource.paginator = this.paginator;
      this.dataSource.sort = this.sort;
    },err=>{
      this.handleError(err)
    })
  }
Run Code Online (Sandbox Code Playgroud)

在控制台中,我看到 API 调用了两次,即使我调用 getAllUser() 的唯一地方是在 Init 方法中

在此处输入图片说明

我仍然无法找到这个问题的原因

javascript httpclient rxjs angular

0
推荐指数
1
解决办法
3625
查看次数