1

我正在尝试使用谷歌云打印。云打印的/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 ();
4

1 回答 1

1

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

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

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

于 2014-08-12T18:57:24.977 回答