我正在用 React Native 编写一个应用程序,我需要发出 API 请求。该服务器运行在具有自签名 SSL 证书的服务器上,因此我需要 Axios 和 React Native 使用自签名证书发出请求并接受响应。
https.Agent,但是在使用 React Native 时这似乎是不可能的(https 模块是节点标准库的一部分,它不包含在 React Native 中),所以这也不是一个有效的解决方案。这是我的项目中的一些示例代码(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 时,一切正常,因此自签名证书绝对是唯一的问题。
我对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)