1

我一直在为 WIndows Mobile 6 开发 Foursquare 应用程序(因为我的合同至少还有 6 个月)我每次尝试发布数据(即签入)都失败了,所以它没有多大用处。关于为什么此代码总是失败的任何建议或指示

oOutStream = request.GetRequestStream();

线 - 请帮助。

        public HTTPPost(Uri Url, Dictionary<string, string> Parameters)
        {
            StringBuilder respBody = new StringBuilder();

            request = (HttpWebRequest)HttpWebRequest.Create(Url);
            request.UserAgent = "4SqLite 20110803";
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.Timeout = 12000000;
            string content = "?";
            foreach (string k in Parameters.Keys)
            {
                content += k + "=" + Parameters[k] + "&";
            }
            content = content.TrimEnd(new char[] { '&' });
            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] byte1 = encoding.GetBytes(content);
            request.ContentLength = byte1.Length;
            byte[] buf = new byte[8192];
            Stream oOutStream = null;
            int tmp = ServicePointManager.DefaultConnectionLimit;
            try
            {
                // send the Post
                oOutStream = request.GetRequestStream();
            }
            catch
            {
                MessageBox.Show("Oops! We couldn't send data to the Internet. Try again later.", "HttpPost: Request error",
                   MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }
            finally
            {
                if (oOutStream != null)
                {
                    oOutStream.Write(byte1, 0, byte1.Length);         //Send it
                    oOutStream.Close();
                }
            }
            try
            {
                // get the response
                response = (HttpWebResponse)request.GetResponse();

                Stream respStream = response.GetResponseStream();

                int count = 0;
                do
                {
                    count = respStream.Read(buf, 0, buf.Length);
                    if (count != 0)
                        respBody.Append(Encoding.ASCII.GetString(buf, 0, count));
                }
                while (count > 0);

                respStream.Close();
                ResponseBody = respBody.ToString();
                EscapedBody = GetEscapedBody();
            }
            catch
            {
                MessageBox.Show("Oops! We couldn't get data from the Internet. Try again later.", "HttpPost: Response error",
                   MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
            }
            finally
            {
                StatusCode = GetStatusLine();
                Headers = GetHeaders();

                response.Close();
            }
4

0 回答 0