【问题标题】:The remote server returned an error: (403) Forbidden. Error远程服务器返回错误:(403) Forbidden。错误
【发布时间】:2014-07-04 08:07:39
【问题描述】:

我正在尝试使用谷歌云打印。云打印的/search api用于获取printerid和xsrf令牌..所以我发布数据并试图获得响应但每次我发布我都得到远程服务器返回错误:(403)禁止..是吗跨域问题还是什么问题?

     string str= TextBox1.Text;
     var request = (HttpWebRequest)WebRequest.Create("https://www.google.com/cloudprint/search?output=json&clientid=" + str);
     request.Method = "POST";
      SetupWebRequest (request);
      string postData = "This is a test that posts this string to a Web server.";
      byte[] byteArray = Encoding.UTF8.GetBytes (postData);
      request.ContentType = "application/x-www-form-urlencoded";
     request.ContentLength = byteArray.Length;
     Stream dataStream = request.GetRequestStream();
     // Write the data to the request stream.
     dataStream.Write(byteArray, 0, byteArray.Length);
     // Close the Stream object.
     dataStream.Close();
     WebResponse response = request.GetResponse ();

【问题讨论】:

  • 您的代码是否设法使用 c# 和谷歌云打印在特定打印机上打印???

标签: .net post httpwebrequest httpwebresponse google-cloud-print


【解决方案1】:

您必须传递 Authorization: Bearer <access token here> 标头才能让 Google 验证您的请求。仅仅在 URL 中传递一个 clientid 参数是不够的。

有关如何获取访问令牌的更多信息,请参阅开发人员指南:

https://developers.google.com/cloud-print/docs/appDevGuide

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-13
    • 1970-01-01
    相关资源
    最近更新 更多