我想让Angular2与我的Asp.Net WebApi 2服务器一起工作.我设法正确处理了一些GET请求,但是这个POST请求表现得很奇怪.我从服务器收到OK(200)响应,但以下代码将其视为错误:
public Register(){
this.accountService.Register(this.Name, this.Password, this.RepeatPassword, this.Email, this.Skype, this.Website).subscribe(
() => { //this is what's supposed to be called, but isn't
this.accountService.Login(this.Name, this.Password).subscribe(
res => {
console.log(res);
localStorage.setItem('token', res);
localStorage.setItem('user', this.Name);
this.router.navigate(['Home']);
},
error2 => {
console.log(error2.Message);
}
);
},
error => { //the response gets here, instead of being handled above
console.log(error.Message);
}
);
}
Run Code Online (Sandbox Code Playgroud)
这是accountService的Register方法:
public Register (userName:string, password:string, confirmPassword:string, email:string, skype:string, website:string)
{
return this.http.post(this.Uri + 'api/Account/Register', JSON.stringify(
{
UserName: userName,
Password: password,
ConfirmPassword: confirmPassword, …Run Code Online (Sandbox Code Playgroud) 执行以下代码时:
import mysql.connector
connection = mysql.connector.connect(...) # connection params here
cursor = connection.cursor()
cursor.execute('create table test_table(value blob)')
cursor.execute('insert into test_table values (_binary %s)', (np.random.sample(10000).astype('float').tobytes(),))
cursor.execute('select * from test_table')
cursor.fetchall()
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
UnicodeDecodeError: 'utf-8' 编解码器无法解码位置 1 中的字节 0xf7:起始字节无效
(...然后是我认为在这里没有用的堆栈跟踪)
似乎 mysql 连接器将我的 blob 转换为字符串(并且没有这样做)。如何在不进行任何转换的情况下将这些数据作为字节获取?