标签: httpclient

如何在 Angular 8 中使用服务实现行为主体

我是 Angular 的新手,但遇到了问题。

我正在创建一个包含多个兄弟组件的应用程序。当我更新一个组件中的值时,其他组件不会更新。我知道要解决这个问题,我应该使用行为主题。但是我如何用我的服务、组件和所有模板来实现它?

这是我的代码 -

---------------我的服务-------------------------- ——

//import


@Injectable() 
export class CoachService {

    apiURL = environment.apiURL;

    constructor(private http: HttpClient ) { }

    coachProfile(token :string)
    {  
    return this.http.post<any>(this.apiURL+'/coach/profile_infos',{
      token: token
      })        
    }

    updateProfile(info: any, token: string, us_id: string) {
      return this.http.post<any[]>(this.apiURL + '/coach/update_profile', {
        token: token,
        us_id: us_id,
        us_lang: info.us_lang,
        us_firstname: info.us_firstname,
        us_lastname: info.us_lastname,
        us_sex: info.us_sex,
        us_birthdate: info.us_birthdate,
        us_national_number : info.us_national_number,
        us_email: info.us_email,
        us_gsm: info.us_gsm,        
        online_profile: info.online_profile,          
        us_address: info.us_address,
        us_zip: info.us_zip,
        us_city: info.us_city,
        country:{
          id: info.country.id …
Run Code Online (Sandbox Code Playgroud)

httpclient typescript behaviorsubject angular angular8

19
推荐指数
2
解决办法
4万
查看次数

Android HttpClient - 证书中的主机名与<example.com>!= <*.example.com>不匹配

我在Android上使用HttpClient连接到https://someUrl.com/somePath.问题是网站的证书是针对*.someUrl.com而不是someUrl.com的,所以我得到了一个SSLException.网站上有跛脚,是的,但除非我能解决这个问题,否则我会陷入困境.有没有办法让HttpClient放松并接受证书?

java ssl android wildcard-subdomain httpclient

18
推荐指数
1
解决办法
3万
查看次数

获取负载测试的NoHttpResponseException

我正在为我的应用程序运行负载测试.我有两个服务器:一个用我的应用程序和一个虚拟服务器负责让我回复.

在我的虚拟服务器中,我有以下jsp代码:

<%@ page import="java.util.Random" %>
<%@ page language="java" %>
<%@ page session="false" %>
<%
   String retVal = "some json string";
   Thread.sleep(50);
%>
Run Code Online (Sandbox Code Playgroud)

我正在使用tomcat7运行应用程序.我的server.xml连接池(在两个服务器中)看起来像:

<Executor name="tomcatThreadPool" namePrefix="catalina-exec-" maxThreads="1500" minSpareThreads="1000" prestartminSpareThreads="true" /> 
<Connector port="9031" protocol="HTTP/1.1" 
           connectionTimeout="20000" 
           maxConnections="4000"
           executor="tomcatThreadPool"
           redirectPort="8443" />
Run Code Online (Sandbox Code Playgroud)

我从服务器运行的java代码是:

 HttpPost post = new HttpPost(bidderUrl);
 post.setHeader("Content-Type", "application/json");    
 // I'm using http client with ThreadSafeClientConnManager
 // total conn = 500,  max conn per route = 100, timeout=500millis
 HttpClient httpClient = httpClientFactory.getHttpClient();
    try {
        post.setEntity(new StringEntity(jsobBidRequest));
        HttpResponse response = httpClient.execute(post);
        ...
    catch …
Run Code Online (Sandbox Code Playgroud)

java tomcat httpclient

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

使用HTTP客户端为JSON列表发送和解析响应

在我的java代码中,我需要向具有3个标头的特定URL发送http post请求:

URL: http://localhost/something
Referer: http://localhost/something 
Authorization: Basic (with a username and password)
Content-type: application/json
Run Code Online (Sandbox Code Playgroud)

这将返回一个响应,其中包含一个JSON"key":"value"对,然后我需要以某种方式解析以将键/值(Alan/72)存储在MAP中.响应是(当使用SOAPUI或Postman Rest时):

    {
    "analyzedNames": [
        {
            "alternate": false               
        }
    ],
    "nameResults": [
        {
            "alternate": false,            
            "givenName": "John",           
            "nameCategory": "PERSONAL",
            "originalGivenName": "",
            "originalSurname": "",           
            "score": 72,
            "scriptType": "NOSCRIPT",            
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

我可以使用SOAPUI或Postman Rest来做到这一点,但是如何在Java中执行此操作,因为我收到错误:

****DEBUG main org.apache.http.impl.conn.DefaultClientConnection - Receiving response: HTTP/1.1 500 Internal Server Error****
Run Code Online (Sandbox Code Playgroud)

我的代码是:

    public class NameSearch {

        /**
         * @param args
         * @throws IOException 
         * @throws ClientProtocolException 
         */
        public static void main(String[] args) throws …
Run Code Online (Sandbox Code Playgroud)

java json httpclient

18
推荐指数
1
解决办法
8万
查看次数

为什么这个HttpClient用法给了我"无法访问已处置的对象".错误?

我已经简化了一些代码,但基本上这一直给我一个"无法访问已处置的对象".错误,我无法解决原因?

我有多个同时运行的任务执行GET,然后解析一些HTML,然后根据GET的结果执行POST.

这段代码所在的方法返回一个带有结果的事件对象,所以我认为我不能使用await,因为该方法需要返回void?

foreach (Account accountToCheck in eventToCheck.accountsToRunOn)
{
    Task.Run(() =>
    {
        HttpClientHandler handler = new HttpClientHandler();
        CookieContainer cookies = new CookieContainer();
        handler.CookieContainer = cookies;
        using (var client = new HttpClient(handler))
        {
            ServicePointManager.ServerCertificateValidationCallback = delegate (object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
            client.Timeout = new TimeSpan(0, 0, 3);
            client.DefaultRequestHeaders.Add("Keep-Alive", "false");
            HttpResponseMessage response = client.GetAsync("https://test.com", HttpCompletionOption.ResponseContentRead).Result;
            string html = response.Content.ReadAsStringAsync().Result;

            var content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair<string, string>("test[username_or_email]",  accountToLogIn.accountHandle),
                new KeyValuePair<string, string>("test[password]",           accountToLogIn.accountPassword)
            });

            var …
Run Code Online (Sandbox Code Playgroud)

c# httpclient

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

httpclient jar冲突.怎么解决?

//这是我的代码,我正在代理...

import org.apache.commons.io.IOUtils;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.DefaultProxyRoutePlanner;

{
HttpHost proxy = new HttpHost("proxyhost", 8082); 
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
HttpClient client = HttpClients.custom().setRoutePlanner(routePlanner).build();
HttpResponse response = client.execute(request);}
Run Code Online (Sandbox Code Playgroud)

//我的控制台上出现以下错误

 Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/http/ssl/SSLContexts
    at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:966)
    at TwitterFeeds.main(TwitterFeeds.java:40)
    Caused by: java.lang.ClassNotFoundException: org.apache.http.ssl.SSLContexts
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 2 more
Run Code Online (Sandbox Code Playgroud)

我正在使用以下罐子

httpclient-4.5.2.jar
httpcore-4.3.jar
Run Code Online (Sandbox Code Playgroud)

java ssl jar httpclient

18
推荐指数
1
解决办法
3万
查看次数

如何从Httpclient解析json字符串

嗨我通过调用外部api获得json结果.

        HttpClient client = new HttpClient();
        client.BaseAddress = new Uri(url);
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        HttpResponseMessage response = client.GetAsync(url).Result;

        if (response.IsSuccessStatusCode)
        {
            var result  = response.Content.ReadAsStringAsync().Result;
            var s = Newtonsoft.Json.JsonConvert.DeserializeObject(result);
            return "Success";
        }
        else
        {
            return "Fail";
        }
Run Code Online (Sandbox Code Playgroud)

var s = Newtonsoft.Json.JsonConvert.DeserializeObject(result);我得到的结果是:

 {{
  "query": "1",
  "topScoringIntent": {
    "intent": "1",
    "score": 0.9978111,
    "actions": [
      {
        "triggered": false,
        "name": "1",
        "parameters": [
          {
            "name": "1",
            "required": true,
            "value": null
          },
          {
            "name": "1",
            "required": true,
            "value": null
          },
          {
            "name": "1",
            "required": true,
            "value": …
Run Code Online (Sandbox Code Playgroud)

c# json httpclient json.net

18
推荐指数
4
解决办法
5万
查看次数

httpclient使用什么端口?

httpclient使用什么端口?

80,8080,......?

networking httpclient

17
推荐指数
3
解决办法
1万
查看次数

URLConnection或HTTPClient:哪个提供更好的功能和更高的效率?

我希望为Android应用程序创建一个登录表单.我想使用post方法将信息发送到服务器端,由PHP文件处理它; 然后验证参数并发回响应.

我看一下使用HttpClient和URLConnection的实现,它们非常相似.哪个在Android应用程序中使用效率更高?

谢谢Fabii

android urlconnection httpclient

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

检测并处理需要登录的wifi

HttpClient在一个Android应用程序中使用4.1,并试图让我的应用程序的API请求被其中一个"你需要登录或支付wifi"屏幕拦截.

我想弹出一个允许用户登录的webview.

我一直试图拦截httpClient中的重定向,但我没有成功.

这就是我目前正在尝试的:

this.client = new DefaultHttpClient(connectionManager, params);

((DefaultHttpClient) this.client).setRedirectStrategy(new DefaultRedirectStrategy() {
    public boolean isRedirected(HttpRequest request, HttpResponse response, HttpContext context)  {
        boolean isRedirect = Boolean.FALSE;
        try {
            isRedirect = super.isRedirected(request, response, context);
        } catch (ProtocolException e) {
            Log.e(TAG, "Failed to run isRedirected", e);
        }
        if (!isRedirect) {
            int responseCode = response.getStatusLine().getStatusCode();
            if (responseCode == 301 || responseCode == 302) {
                throw new WifiLoginNeeded();
                // The "real implementation" should return true here..
            }
        } else {
            throw new …
Run Code Online (Sandbox Code Playgroud)

android httpclient wifi

17
推荐指数
1
解决办法
2212
查看次数