我正在尝试在Angular中发出请求,我知道HTTP响应不是JSON而是文本.但是,Angular似乎期待JSON响应,因为错误如下:
SyntaxError:XMLHttpRequest.c中JSON.parse()位置0的JSON中的意外标记<
以及
解析http:// localhost:9时出现 Http失败...
这是post方法:
return this.http.post(this.loginUrl, this.createLoginFormData(username, password), this.httpOptions)
.pipe(
tap( // Log the result or error
data => console.log(data);
error => console.log(error)
)
);
Run Code Online (Sandbox Code Playgroud)
和标题.
private httpOptions = {
headers: new HttpHeaders({
'Accept': 'text/html, application/xhtml+xml, */*',
'Content-Type': 'application/x-www-form-urlencoded',
responseType: 'text'
},
) };
Run Code Online (Sandbox Code Playgroud)
我认为这responseType: 'text'足以让Angular期望非JSON响应.
这是我的问题:我想映射文件"filename.txt",它基本上由每行两对字符串组成:
"string1 string2
string3 string4
string5 string6..."
Run Code Online (Sandbox Code Playgroud)
然后我想用strtok分隔不同的字符串.
所以我像这样映射文件:
// open file
if ((fdsrc = open("filename.txt", O_RDONLY)) < 0) {
fprintf(stderr, "src open error");
exit(1);
}
// get the size of the file
if (fstat(fdsrc, &statbuf) < 0) {
fprintf(stderr, "fstat error");
exit(1);
}
// mmap the file
if ((src = mmap(0, statbuf.st_size, PROT_READ, MAP_SHARED, fdsrc, 0)) == (caddr_t) -1) {
fprintf(stderr, "mmap src");
exit(1);
}
Run Code Online (Sandbox Code Playgroud)
当我跑线
printf("src: %s \n", src);
Run Code Online (Sandbox Code Playgroud)
它正确打印文件的内容!
但是当我试图分开这些词时
char* token;
token = strtok(src, " \n"); …Run Code Online (Sandbox Code Playgroud)