小编par*_*asm的帖子

我尝试打开URL时为什么会收到403错误

我目前正在使用http://imdbapi.org上的imdb api 来获取有关电影的一些信息.当我使用API​​并尝试在java中打开此URL时,它给出了403错误.url应该以JSON格式返回数据.这是我到目前为止的代码(Java 7):

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class Test {
    public static void main(String[] args) {
        URL url =null;
        try {
            url = new URL("http://imdbapi.org/?q=batman");
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        InputStream is =null;
        try {
            is = url.openConnection().getInputStream();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        BufferedReader reader = new BufferedReader( new InputStreamReader( is ) …
Run Code Online (Sandbox Code Playgroud)

java api imdb

8
推荐指数
1
解决办法
6260
查看次数

为什么chrome.cookies在内容脚本中未定义?

每当我尝试使用该chrome.cookies.get()函数从cookie中读取时,我都会收到此错误:

TypeError: Cannot read property 'get' of undefined.
Run Code Online (Sandbox Code Playgroud)

我在我的content.js文件中调用该函数,它只能在twitter.com上运行(该部分有效).

这是我的清单文件:

{
  "manifest_version": 2,

  "name": "Twitter-MultiSignin",
  "description": "twiter sign in",
  "version": "1.0",
  "permissions": [ "cookies", "alarms" , "http://*/*", "https://*/*", "storage"],
  "content_scripts": [{
    "matches": ["http://twitter.com/*","https://twitter.com/*"],
    "js": ["jquery.js","content.js"]
  }],
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  }
}
Run Code Online (Sandbox Code Playgroud)

这是我的content.js(它总是在twitter页面上提醒,以便工作正常):

$(function() {
    alert('got here');
    try{
        chrome.cookies.get({ url: 'https://twitter.com', name: 'auth_token' }, function (cookie){
            alert(cookie.value);
        });
    }catch(err){
        //do nothing
        alert(err);
    }
    try{
        chrome.cookies.get({ url: 'https://twitter.com', name: 'twid' },
        function (cookie) {
            if (cookie) { …
Run Code Online (Sandbox Code Playgroud)

google-chrome google-chrome-extension content-script

8
推荐指数
1
解决办法
7598
查看次数