在Windows Service应用程序中使用C#,JSON4.5,REST格式的.Net对象想要上传到数据库并查询。
我正在尝试找出连接到使用WebClient.UploadString()的Firebase所需的URI的正确语法,之前我已经成功地使用了下面的代码来上传到GAS数据库。但我们现在正在迁移到Firebase。我已经设法使用OAuth2应用程序接口动态获取了一个访问令牌,大概我需要将它包含在我在方法调用中使用的URI中。有没有人有一小段文字字符串的代码,以便我能看到正确的语法?我还怀疑头文件可能需要不同的值?
WebClient webClnt = new WebClient();
webClnt.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
string result =
webClnt
.UploadString(
new Uri("https://myfirebaseDB123.firebaseio.com/????"),
JSONObjectStr);干杯,
安迪
发布于 2016-11-17 06:49:09
感谢谷歌的支持,指出了语法上的细微变化,使C#与Firebase的交互得以成功:
var connectionString = FirebaseServerURL + ".json?access_token=" + accessToken;
var webClnt = new WebClient();
result = webClnt.UploadString(connectionString, "PATCH", data); 因此,在URI和业务中使用"access_token=“而不是"auth=”。不需要在webClnt中设置额外的“web headers”。
注意当使用"Auth“时,返回的是http 400 (错误请求),而不是401 (未经授权)。而如果没有尝试认证,则返回401。
https://stackoverflow.com/questions/40393788
复制相似问题