【问题标题】:Curl - Invalid XML format for MyAnimeList ApiCurl - MyAnimeList Api 的 XML 格式无效
【发布时间】:2017-12-21 19:58:12
【问题描述】:

所以我想使用 curl 使用 MyAnimeList Api 更新我的特定系列列表中的剧集。当我想发布 XML 数据时,它会给我一个Invalid XML format 响应。我看到一些帖子说您应该先对数据进行编码,但这并没有解决它(使用在线工具,如this onethis one)。

curl -u "<dummyuser>:<dummypass>" -d data="<?xml version="1.0" encoding="UTF-8"?><entry><episode>18</episode><status>1</status><score>7</score><storage_type></storage_type><storage_value></storage_value><times_rewatched></times_rewatched><rewatch_value></rewatch_value><date_start></date_start><date_finish></date_finish><priority></priority><enable_discussion></enable_discussion><enable_rewatching></enable_rewatching><comments></comments><tags></tags></entry>" -k https://myanimelist.net/api/animelist/update/7791.xml

感谢任何帮助。

【问题讨论】:

  • 我当然希望现在情况会好一些,但是 iirc,几年前,他们的 api 显然是由一群智障喝醉的猴子写的

标签: php xml curl


【解决方案1】:
  1. 使用GET 而不是POST
  2. 对数据进行 URL 编码

    curl -u "username:password" -d data="%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%3Centry%3E%3Cepisode%3E18%3C%2Fepisode%3E%3Cstatus%3E1%3C%2Fstatus%3E%3Cscore%3E7%3C%2Fscore%3E%3Cstorage_type%3E%3C%2Fstorage_type%3E%3Cstorage_value%3E%3C%2Fstorage_value%3E%3Ctimes_rewatched%3E%3C%2Ftimes_rewatched%3E%3Crewatch_value%3E%3C%2Frewatch_value%3E%3Cdate_start%3E%3C%2Fdate_start%3E%3Cdate_finish%3E%3C%2Fdate_finish%3E%3Cpriority%3E%3C%2Fpriority%3E%3Cenable_discussion%3E%3C%2Fenable_discussion%3E%3Cenable_rewatching%3E%3C%2Fenable_rewatching%3E%3Ccomments%3E%3C%2Fcomments%3E%3Ctags%3E%3C%2Ftags%3E%3C%2Fentry%3E" -k https://myanimelist.net/api/animelist/update/7791.xml -g
    

【讨论】:

    【解决方案2】:

    在您的 curl 语句中,标记值的引号与用于标记 XML 字符串的引号相同(例如 version="1.0")。所以在整个 -d 值周围使用单引号...

    curl -u "<dummyuser>:<dummypass>" -d data='<?xml version="1.0" encoding="UTF-8"?><entry><episode>18</episode><status>1</status><score>7</score><storage_type></storage_type><storage_value></storage_value><times_rewatched></times_rewatched><rewatch_value></rewatch_value><date_start></date_start><date_finish></date_finish><priority></priority><enable_discussion></enable_discussion><enable_rewatching></enable_rewatching><comments></comments><tags></tags></entry>' -k https://myanimelist.net/api/animelist/update/7791.xml
    

    【讨论】:

    • 已经尝试过单引号。报错:&lt; was unexpected at this time.
    猜你喜欢
    • 1970-01-01
    • 2013-09-10
    • 2015-07-24
    • 2011-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多