【问题标题】:Some error when get data from HTTP request with post使用 post 从 HTTP 请求获取数据时出现一些错误
【发布时间】:2015-07-20 01:41:23
【问题描述】:

我按照HTTP request with post 的说明从站点:http://www.tudienabc.com/phat-am-tieng-nhat 获取音频文件(该站点允许我们输入英文或日文单词/短语/句子并生成音频文件,看起来像“/pronunciations /audio?file_name=1431134309.002.mp3&file_type=mp3" 在回发后 HTML 代码的第 129 行)。

但是,我从自己的应用程序中获得的音频文件与从本网站生成的音频文件不同。本网站生成的音频文件(mp3)可以在www.tudienabc.com/pronunciations/播放(如:www.tudienabc.com/pronunciations/audio?file_name=1431141268.9947.mp3&file_type=mp3),但生成的音频文件从我的应用程序无法播放(例如:www.tudienabc.com/pronunciations/audio?file_name=1431141475.4908.mp3&file_type=mp3)。

那么,有什么问题吗?以及如何获取准确的音频文件?

这是我的代码:

var request = (HttpWebRequest)WebRequest.Create("http://www.tudienabc.com/phat-am-tieng-nhat");

var postData = "_method=POST&data[Pronun][text]=hello&data[Pronun][type]=3";
var data = Encoding.ASCII.GetBytes(postData);

request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;

using (var stream = request.GetRequestStream())
{
    stream.Write(data, 0, data.Length);
}

var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

int m = responseString.IndexOf("pronunciations/audio?file_name=")+"pronunciations/audio?file_name=".Length;
int n = responseString.IndexOf("&file_type=mp3");
string filename = responseString.Substring(m, n - m);

return filename;

谢谢,

【问题讨论】:

  • 向我们展示您使用的代码。
  • 这不是“你的”代码,而是执行相同任务的几种方法。发布“你的”代码,这样我们就可以看到它有什么问题。与其尝试猜测您选择了哪个选项来复制粘贴不同的答案,而只是为了发现您在编辑时不小心删除了逗号。
  • 对不起,菲耶。这是我第一次将问题发布到stackoverflow,所以我遇到了一些麻烦。当我按 Enter 进入新行时,它会发布我的评论。 :) 我用我的代码编辑了我的问题,因为评论不允许长文本。谢谢。

标签: c# http post


【解决方案1】:

他们的网站使用 ECMAScript 处理音频

<script>
       var wait = new waitGenerateAudio(
         '#progress_audio_placeholder',
         '/pronunciations/checkFinish/1431151184.739',
         'aGVsbG8gZnlyeWU=',
         '/pronunciations/audio?file_name=1431151184.739.mp3&amp;file_type=mp3',
         'T?o file l?i'
       );
 </script>

您需要能够处理要创建的音频文件的 JavaScript。

结帐 C# httpwebrequest and javascript 要么 WebClient runs javascript

用于使用无头浏览器。

我建议研究一个更通用的文本到音频库。 https://gist.github.com/alotaiba/1728771

【讨论】:

  • 谢谢。但根据您的建议(stackoverflow.com/questions/516027/c-sharp-httpwebrequest-and-javascript): 我的代码: wb.Navigate("tudienabc.com/phat-am-tieng-nhat", null, postdata, null);但是循环 while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); } 无法完成。所以,我无法得到响应数据。使用 Google Text to Speech API,它不能按照性别(男性、女性)返回音频,并且它不是我需要的站点。你有什么办法解决我的问题吗?谢谢,
猜你喜欢
  • 1970-01-01
  • 2016-05-03
  • 2017-06-23
  • 2017-09-09
  • 1970-01-01
  • 1970-01-01
  • 2013-12-11
  • 1970-01-01
  • 2016-08-25
相关资源
最近更新 更多