小编b3n*_*m1n的帖子

React Native Axios 允许自签名 ssl 证书

我正在用 React Native 编写一个应用程序,我需要发出 API 请求。该服务器运行在具有自签名 SSL 证书的服务器上,因此我需要 Axios 和 React Native 使用自签名证书发出请求并接受响应。

  • 我无法从官方证书颁发机构获得证书。
  • 我已经尝试过使用https.Agent,但是在使用 React Native 时这似乎是不可能的(https 模块是节点标准库的一部分,它不包含在 React Native 中),所以这也不是一个有效的解决方案。
  • 我更愿意继续使用 Axios,但是如果有任何具有类似功能的库,我会考虑切换库(我已经尝试过一些,但没有提供允许自签名证书的功能)。

这是我的项目中的一些示例代码(url 是服务器的 IP):

import axios from 'axios';

const instance = axios.create({ });
instance.get(url)
    .then(res => {
        this.setState({dataSource: res.data});
     })

Run Code Online (Sandbox Code Playgroud)

顺便说一句,当我使用 ngrok 时,一切正常,因此自签名证书绝对是唯一的问题。

javascript https android react-native axios

7
推荐指数
1
解决办法
5252
查看次数

C从字符串中删除特殊字符

我对C非常陌生,并且创建了一个函数,该函数从字符串中删除特殊字符并返回一个新字符串(不包含特殊字符)。

乍一看,这似乎运行良好,现在我需要在一个(巨大的)文本文件(一百万个句子)的行上运行此功能。经过几千行/句(大约4,000个)之后,我遇到了段错误。

我对C中的内存分配和字符串没有太多的经验,但我尝试找出代码的问题,很不幸,这没有任何运气。这是代码:

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

char *preproccessString(char *str) {
    // Create a new string of the size of the input string, so this might be bigger than needed but should never be too small
    char *result = malloc(sizeof(str));
    // Array of allowed chars with a 0 on the end to know when the end of the array is reached, I don't know if there is a more elegant way to do this
    // Changed from array …
Run Code Online (Sandbox Code Playgroud)

c string replace char segmentation-fault

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