我正在尝试将视频上传到Wordpress。使用以下方法
string expression = videoData.VideoTitle;
string str7 = videoData.VideoTitle;
WebClient client = new WebClient();
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
string s = "security_code=JGZpbGVu&post_content=<iframe width='480' height='390' src='http://www.youtube.com/embed/XkIdmC8MlkI' frameborder='0' allowfullscreen></iframe>"
+ "&post_title=" + expression + "&post_category="
+ "&post_category=" + category + "&category=" + category + "&post_name=" + str7 + "&post_date=" + DATE_STRING;
byte[] bytes = Encoding.ASCII.GetBytes(s);
byte[] buffer2 = client.UploadData(uploadPath, "POST", bytes);
string str8 = Encoding.ASCII.GetString(buffer2).ToString();
它有效并且所有内容都已发布但标签中的内容未发布我尝试了一些事情,结果发现它有标签问题。 当我删除&lt; iframe标签显示但直到url,之后一切都消失了。 这是表现不佳的事情
"security_code=JGZpbGVu&post_content=test iframe width='480' height='390' src='http://www.youtube.com/embed/XkIdmC8MlkI' frameborder='0' allowfullscreen></iframe>&post_title=How to build, upgrade, or repair, your own PC Computer&post_category=&post_category=asd&category=asd&post_name=How to build, upgrade, or repair, your own PC Computer&post_date=2011-05-11 00:00:00"
任何想法有什么问题?
答案 0 :(得分:1)
您可能需要URL-encode HTML。
确保您引用System.Web,然后:
string html = @"<iframe width='480' height='390' src='http://www.youtube.com/embed/XkIdmC8MlkI' frameborder='0' allowfullscreen></iframe>";
string s = string.Format("security_code=JGZpbGVu&post_content={0}&post_title={1}&post_category={2}&category={3}&post_name={4}&post_date={5}", System.Web.HttpUtility.UrlEncode(html), expression, category, category, str7, DATE_STRING);