小编Tim*_*Tim的帖子

如何查看从httppost发送的字符串?

下面是一段试图发布到本地服务器上的PHP脚本的代码片段.我正在将数据传回服务器的MySQL表,因为数据量非常小,我想我会使用HttpClient将数据嵌入到URL参数中.

但是,即使我从服务器获得的响应是​​正常的(HTTP代码= 200),很明显服务器端PHP脚本没有获得正确格式化的数据(对MySQL表没有影响).但是,当我在浏览器中手动输入URL + args时,如下所示:

http://10.0.0.13/jobs_returndata_test.php?jobnum=189193&pnum=3&entime=13:00&extime=14:00 
Run Code Online (Sandbox Code Playgroud)

例如,一切正常(PHP脚本正确写入MySQL表).

我的问题:我有没有办法真正查看HttpClient发送的内容?(即HttpPost对象的整个.toString内容?).这是Android端代码段:

// Create a new HttpClient and Post Header, send data as args to PHP file
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.0.13/jobs_returndata.php");
try {
    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("jobnum",convertSimple(jobNum)));
    nameValuePairs.add(new BasicNameValuePair("pnum",convertSimple(rowNum)));
    nameValuePairs.add(new BasicNameValuePair("entime",enteredInTime));
    nameValuePairs.add(new BasicNameValuePair("extime",enteredOutTime));

    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    Log.i("HTTP Post", "Execute Post sending jobnum="+ convertSimple(jobNum) +      
    "&pnum="+ convertSimple(rowNum) + "&entime=" + enteredInTime
                    + "&extime=" + enteredOutTime);
    // Execute HTTP Post Request
    HttpResponse response = httpclient.execute(httppost);
    Log.i("HTTP Post", "Response …
Run Code Online (Sandbox Code Playgroud)

string url android httpclient http-post

2
推荐指数
1
解决办法
4643
查看次数

初始化集合的简明方法

我可以使用以下内容以简洁的方式初始化类:

public static readonly type TYPE_NAME = new type()
        {
            ClientIp = "ClientIp",
            LanguageCode = "LanguageCode",
            SessionToken = "SessionToken",
            SystemKey = "SystemKey"
        };
Run Code Online (Sandbox Code Playgroud)

但是,是否可以以类似的方式初始化集合(继承自List<>)?

c# collections

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

字符串结果成多行文本框

我一直试图在我的TextBox中获得多个结果,但我无法做到正确.有人可以告诉我一个将这个数组显示在文本框中的例子吗?

public ArrayList GetUserGroups(string sUserName)
{
    textBox1.Multiline = true;
    ArrayList myItems = new ArrayList();
    UserPrincipal oUserPrincipal = GetUser(sUserName);

    PrincipalSearchResult<Principal> oPrincipalSearchResult = oUserPrincipal.GetGroups();
    textBox1.Multiline = true;
    foreach (Principal oResult in oPrincipalSearchResult)
    {
        myItems.Add(oResult.Name);
        textBox1.Text = oResult.Name.ToString();
    }
    return myItems;
}
Run Code Online (Sandbox Code Playgroud)

.net c# windows .net-3.5

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

如何在datetimepicker中设置当年第一个月的第一天

如何设置当年第一个月的第一天DateTimePicker.

例如.我想在这个时间格式中显示DateTimePicker:

01/01/2013
Run Code Online (Sandbox Code Playgroud)

c# winforms

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

寻找错误的命名空间?

我有一些名称空间问题令我困惑,为什么会发生这种情况.

在下面的代码中,System.IO和System.Reflection试图引用abc.System,而不是使用我在顶部声明的System命名空间.这是为什么?

using System;
using System.Collections.Generic;
using System.Data.OleDb;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc.Data
{
public sealed class Access
{
    public static void Open(string dbPath)
    {
         // error here referencing abc.System in System.IO, and System.Reflection.

         string appPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);         }
}
Run Code Online (Sandbox Code Playgroud)

然后我在另一个文件中有另一个命名空间,如下所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc.System
{
     public static class DateTimeExtensions
     {
    // Implemented from
    // http://stackoverflow.com/questions/38039/how-can-i-get-the-datetime-for-the-start-of-the-week
    public static DateTime StartOfWeek(this DateTime dt, DayOfWeek startOfWeek)
    {
        int diff …
Run Code Online (Sandbox Code Playgroud)

.net c#

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

Asp.net中内联查询中的SQL查询问题

我的sql表结构是这样的

ID  DataName
1   Lipsum lorem 
3   lipsum's lorem
Run Code Online (Sandbox Code Playgroud)

我在asp.net中的内联查询就是这样

select * from table where DataName like 'lipsum's lorem'
Run Code Online (Sandbox Code Playgroud)

它给出了以下错误:

Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 's'.
Msg 105, Level 15, State 1, Line 1
Unclosed quotation mark after the character string ''.
Run Code Online (Sandbox Code Playgroud)

我不想创建一个存储过程来防止这种情况,我希望使用内联查询来解决这个问题.

sql sql-server asp.net sql-server-2005 sql-server-2008

0
推荐指数
1
解决办法
1447
查看次数

C++数组上没有打印任何内容

我是C++的新手.我通常用C#编程,所以我遇到了数组和循环的麻烦.当我尝试使用循环打印动态数组的内容时,它表示请求区域已损坏...例如,我将让它识别与数组内容一起使用的条件但不打印它的内容:

// Array.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void main()
{
    int size=3;
    int *p;
    int myarray[10];
    myarray[3]=4;
    p=new int[size];
    p[2]=3;
    if(myarray[3]==4){
        cout << myarray[3] +"/n";
        cout << "Why?";
    }
    else
        cout << "Not equal " << endl;
    cin.get();
    delete [] p;
}
Run Code Online (Sandbox Code Playgroud)

c++ visual-studio-2010

0
推荐指数
1
解决办法
155
查看次数

从List <T>中删除所有元素

当用户在消息框上单击"是"时,我正在尝试删除所有元素,但我不确定如何删除按钮上的所有项目.我能够删除索引处的元素,但不能删除所有元素.

这是我成功删除索引元素的方法:

public void DeleteAt(int anIndex)
{
    if(CheckIndex(anIndex))
    m_list.RemoveAt(anIndex);
} 
Run Code Online (Sandbox Code Playgroud)

但我想删除所有元素.我试过这样做:

public void DeleteAll()
{
      m_list.RemoveAll();
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用,它说需要有一个参数,RemoveAll();但我不知道什么样的参数.

c# removeall

0
推荐指数
1
解决办法
3258
查看次数

PHP修剪数组中的最后一个字符

我是PHP的新手,我所要做的就是获取所有选定的值并打印出来用逗号分隔它们,但是,我需要在列表中的最后一项之后删除最后一个逗号.

<?php $favoriteFruit = get_post_meta($post->ID, 'Favorite Fruit', false) ?>
<?php if ($favoriteFruit != null): ?>
    <attribute key="FavoriteFruit" 
               value="<?php foreach($favoriteFruit as $fruit){
                                    echo $fruit.',';
                            } ?>"
               />
<?php endif ?>
Run Code Online (Sandbox Code Playgroud)

这个打印出列表中的所有项目,不会删除最后一个逗号.有任何想法吗?

php xml arrays wordpress list

-1
推荐指数
1
解决办法
921
查看次数